Skip to content

Commit

Permalink
openvidu-test-e2e: reduce tests flakyness with active waits
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloFuente committed Oct 21, 2024
1 parent 333436a commit 9f4bcc8
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -445,29 +445,22 @@ void enableDisableTrackTest() throws Exception {
// An enabled subscribed track increases its bytesReceived over time

long bytesReceived = this.getSubscriberVideoBytesReceived(user, subscriberVideo);
Thread.sleep(500);
Assertions.assertTrue(bytesReceived < this.getSubscriberVideoBytesReceived(user, subscriberVideo),
"Subscriber enabled should have increased its bytesReceived");

user.getDriver().findElement(By.id("close-dialog-btn")).click();
Thread.sleep(300);
this.waitUntilSubscriberBytesReceivedIncrease(user, subscriberVideo, bytesReceived);

// A disabled subscribed track does not increase its bytesReceived over time
WebElement enableToggle = user.getDriver()
.findElement(By.cssSelector("#openvidu-instance-1 .toggle-video-enabled"));
enableToggle.click();
bytesReceived = this.getSubscriberVideoBytesReceived(user, subscriberVideo);
Thread.sleep(1000);
Thread.sleep(1250);
Assertions.assertEquals(bytesReceived, this.getSubscriberVideoBytesReceived(user, subscriberVideo),
"Subscriber disabled should have NOT increased its bytesReceived");

user.getDriver().findElement(By.id("close-dialog-btn")).click();
Thread.sleep(300);

enableToggle.click();
Thread.sleep(500);
Assertions.assertTrue(bytesReceived < this.getSubscriberVideoBytesReceived(user, subscriberVideo),
"Subscriber enabled should have increased its bytesReceived");
this.waitUntilSubscriberBytesReceivedIncrease(user, subscriberVideo, bytesReceived);

gracefullyLeaveParticipants(user, 2);
}
Expand Down Expand Up @@ -514,8 +507,7 @@ void enableDisableTrackWithDynacastTest() throws Exception {
this.waitUntilPublisherLayerActive(user, publisherVideo, "q", false);

firstSubscriberToggle.click();
Assertions.assertTrue(bytesReceived < this.getSubscriberVideoBytesReceived(user, subscriberVideo1),
"Subscriber enabled should have increased its bytesReceived");
this.waitUntilSubscriberBytesReceivedIncrease(user, subscriberVideo1, bytesReceived);
this.waitUntilPublisherLayerActive(user, publisherVideo, "f", true);
this.waitUntilPublisherLayerActive(user, publisherVideo, "h", true);
this.waitUntilPublisherLayerActive(user, publisherVideo, "q", true);
Expand Down Expand Up @@ -824,13 +816,14 @@ void adaptiveStreamDisabledDynacastDisabledTest() throws Exception {
Assertions.assertTrue(user.getBrowserUser().assertAllElementsHaveTracks("video", false, true),
"HTMLVideoElements were expected to have only one audio track");

// Some time for the subscriber's track to settle in one simulcasted resolution
Thread.sleep(3000);

WebElement subscriberVideo = user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 video.remote"));

int oldFrameWidth = this.getSubscriberVideoFrameWidth(user, subscriberVideo);
user.getBrowserUser().changeElementSize(subscriberVideo, 1000, 700);
Thread.sleep(2300);
Thread.sleep(2000);
int newFrameWidth = this.getSubscriberVideoFrameWidth(user, subscriberVideo);

Assertions.assertEquals(oldFrameWidth, newFrameWidth,
Expand Down Expand Up @@ -1110,6 +1103,13 @@ private void waitUntilSubscriberFrameWidthChanges(OpenViduTestappUser user, WebE
}
}

private void waitUntilSubscriberBytesReceivedIncrease(OpenViduTestappUser user, WebElement videoElement,
final long previousBytesReceived) {
this.waitUntilAux(user, videoElement, () -> {
return this.getSubscriberVideoBytesReceived(user, videoElement) > previousBytesReceived;
}, "Timeout waiting for subscriber track to increase its bytesReceived from " + previousBytesReceived);
}

private void waitUntilPublisherLayerActive(OpenViduTestappUser user, final WebElement publisherVideo,
final String rid, final boolean active) {
this.waitUntilAux(user, publisherVideo, () -> {
Expand Down

0 comments on commit 9f4bcc8

Please sign in to comment.