openvidu-test-e2e: Fix streamPropertyChangedEventTest race condition.

This supposedly fix a flaky test. If the event reaches before the viewport resolution is known, test would fail.
Now the viewport resolution is adquired in a new Thread and the resolution is not compared until the event
and viewport resolution are received
pull/732/head
cruizba 2022-06-02 15:08:30 +02:00
parent b80ca191e2
commit e8fae9bf0f
1 changed files with 25 additions and 13 deletions

View File

@ -931,6 +931,7 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
} }
// Resize captured window // Resize captured window
final CountDownLatch latchViewport = new CountDownLatch(1);
final CountDownLatch latch3 = new CountDownLatch(2); final CountDownLatch latch3 = new CountDownLatch(2);
int newWidth = 1000; int newWidth = 1000;
int newHeight = 700; int newHeight = 700;
@ -938,26 +939,37 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
final long[] expectedWidthHeight = new long[2]; final long[] expectedWidthHeight = new long[2];
user.getEventManager().on("streamPropertyChanged", (event) -> { user.getEventManager().on("streamPropertyChanged", (event) -> {
String expectedDimensions = "{\"width\":" + expectedWidthHeight[0] + ",\"height\":" + expectedWidthHeight[1] try {
+ "}"; if (latchViewport.await(4000, TimeUnit.MILLISECONDS)) {
System.out.println("Publisher dimensions: " + event.get("newValue").getAsJsonObject().toString()); String expectedDimensions = "{\"width\":" + expectedWidthHeight[0] + ",\"height\":" + expectedWidthHeight[1]
System.out.println("Real dimensions of viewport: " + expectedDimensions); + "}";
if ("videoDimensions".equals(event.get("changedProperty").getAsString()) System.out.println("Publisher dimensions: " + event.get("newValue").getAsJsonObject().toString());
&& "screenResized".equals(event.get("reason").getAsString()) System.out.println("Real dimensions of viewport: " + expectedDimensions);
&& expectedDimensions.equals(event.get("newValue").getAsJsonObject().toString())) { if ("videoDimensions".equals(event.get("changedProperty").getAsString())
latch3.countDown(); && "screenResized".equals(event.get("reason").getAsString())
&& expectedDimensions.equals(event.get("newValue").getAsJsonObject().toString())) {
latch3.countDown();
}
}
} catch (InterruptedException e) {
log.error("Error waiting for viewport resolution");
} }
}); });
user.getDriver().manage().window().setSize(new Dimension(newWidth, newHeight)); user.getDriver().manage().window().setSize(new Dimension(newWidth, newHeight));
String widthAndHeight = user.getEventManager().getDimensionOfViewport();
JsonObject obj = JsonParser.parseString(widthAndHeight).getAsJsonObject();
expectedWidthHeight[0] = obj.get("width").getAsLong(); new Thread(() -> {
expectedWidthHeight[1] = obj.get("height").getAsLong(); String widthAndHeight = user.getEventManager().getDimensionOfViewport();
JsonObject obj = JsonParser.parseString(widthAndHeight).getAsJsonObject();
System.out.println("New viewport dimension: " + obj.toString()); expectedWidthHeight[0] = obj.get("width").getAsLong();
expectedWidthHeight[1] = obj.get("height").getAsLong();
System.out.println("New viewport dimension: " + obj.toString());
latchViewport.countDown();
}).start();
user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 6); user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 6);