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
final CountDownLatch latchViewport = new CountDownLatch(1);
final CountDownLatch latch3 = new CountDownLatch(2);
int newWidth = 1000;
int newHeight = 700;
@ -938,6 +939,8 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
final long[] expectedWidthHeight = new long[2];
user.getEventManager().on("streamPropertyChanged", (event) -> {
try {
if (latchViewport.await(4000, TimeUnit.MILLISECONDS)) {
String expectedDimensions = "{\"width\":" + expectedWidthHeight[0] + ",\"height\":" + expectedWidthHeight[1]
+ "}";
System.out.println("Publisher dimensions: " + event.get("newValue").getAsJsonObject().toString());
@ -947,10 +950,16 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
&& 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));
new Thread(() -> {
String widthAndHeight = user.getEventManager().getDimensionOfViewport();
JsonObject obj = JsonParser.parseString(widthAndHeight).getAsJsonObject();
@ -958,6 +967,9 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
expectedWidthHeight[1] = obj.get("height").getAsLong();
System.out.println("New viewport dimension: " + obj.toString());
latchViewport.countDown();
}).start();
user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 6);