From e307af24e3443262204b3f0f3d6e08bbfc972f18 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Mon, 30 Sep 2024 15:19:33 +0200 Subject: [PATCH] openvidu-test-e2e: improved e2e tests --- .../test/e2e/OpenViduEventManager.java | 6 ++--- .../io/openvidu/test/e2e/OpenViduTestE2e.java | 21 +++++++++++++-- .../e2e/AbstractOpenViduTestappE2eTest.java | 2 +- .../test/e2e/OpenViduTestAppE2eTest.java | 26 +++++++++++++++---- .../openvidu-instance.component.ts | 23 ++++++++++++++++ .../participant/participant.component.ts | 19 +++++++++++++- .../test-scenarios.component.ts | 4 +++ 7 files changed, 89 insertions(+), 12 deletions(-) diff --git a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/OpenViduEventManager.java b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/OpenViduEventManager.java index 018408be5d..bfdbf7c83c 100644 --- a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/OpenViduEventManager.java +++ b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/OpenViduEventManager.java @@ -130,7 +130,7 @@ public void uncaughtException(Thread th, Throwable ex) { this.getEventsFromBrowser(); this.emitEvents(); try { - Thread.sleep(25); + Thread.sleep(75); } catch (InterruptedException e) { } } @@ -197,7 +197,7 @@ public void waitUntilEventReaches(String eventType, String eventCategory, int ev CountDownLatch eventSignal = new CountDownLatch(eventNumber); this.setCountDown(eventType + "-" + eventCategory, eventSignal); try { - if (!eventSignal.await(secondsOfWait * 1000, TimeUnit.MILLISECONDS)) { + if (!eventSignal.await(secondsOfWait, TimeUnit.SECONDS)) { if (printTimeoutError) { String screenshot = "data:image/png;base64," + ((TakesScreenshot) driver).getScreenshotAs(BASE64); System.out.println("TIMEOUT SCREENSHOT"); @@ -218,7 +218,7 @@ public void waitUntilEventReaches(int numberOfUser, String eventType, String eve CountDownLatch eventSignal = new CountDownLatch(eventNumber); this.setCountDown(numberOfUser, eventType + "-" + eventCategory, eventSignal); try { - if (!eventSignal.await(secondsOfWait * 1000, TimeUnit.MILLISECONDS)) { + if (!eventSignal.await(secondsOfWait, TimeUnit.SECONDS)) { if (printTimeoutError) { String screenshot = "data:image/png;base64," + ((TakesScreenshot) driver).getScreenshotAs(BASE64); System.out.println("TIMEOUT SCREENSHOT"); diff --git a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/OpenViduTestE2e.java b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/OpenViduTestE2e.java index de0a92c528..c64ef8b2ac 100644 --- a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/OpenViduTestE2e.java +++ b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/OpenViduTestE2e.java @@ -37,6 +37,8 @@ import io.openvidu.test.browsers.FirefoxUser; import io.openvidu.test.browsers.utils.BrowserNames; import io.openvidu.test.browsers.utils.CommandLineExecutor; +import livekit.LivekitModels.Room; +import retrofit2.Response; public class OpenViduTestE2e { @@ -383,8 +385,23 @@ private void stopContainerIfPossible(GenericContainer container) { protected void closeAllRooms(RoomServiceClient client) { try { - client.listRooms().execute().body().forEach(r -> client.deleteRoom(r.getName())); - } catch (IOException e) { + Response> response = client.listRooms().execute(); + if (response.isSuccessful()) { + List roomList = response.body(); + if (roomList != null) { + client.listRooms().execute().body().forEach(r -> { + log.info("Closing existing room " + r.getName()); + try { + log.info("Response: " + client.deleteRoom(r.getName()).execute().code()); + } catch (IOException e) { + log.error("Error closing room " + r.getName(), e); + } + }); + } + } else { + log.error("Error listing rooms: " + response.errorBody()); + } + } catch (Exception e) { log.error("Error closing rooms: {}", e.getMessage()); } } diff --git a/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/AbstractOpenViduTestappE2eTest.java b/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/AbstractOpenViduTestappE2eTest.java index 9eb7b90786..5ad5b6058a 100644 --- a/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/AbstractOpenViduTestappE2eTest.java +++ b/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/AbstractOpenViduTestappE2eTest.java @@ -40,7 +40,7 @@ protected OpenViduTestappUser setupBrowserAndConnectToOpenViduTestapp(String bro protected void gracefullyLeaveParticipants(OpenViduTestappUser user, int numberOfParticipants) throws Exception { int accumulatedDisconnected = 0; for (int j = 1; j <= numberOfParticipants; j++) { - user.getDriver().findElement(By.id("remove-user-btn")).sendKeys(Keys.ENTER); + user.getDriver().findElement(By.className("disconnect-btn")).sendKeys(Keys.ENTER); user.getEventManager().waitUntilEventReaches("disconnected", "RoomEvent", j); accumulatedDisconnected = (j != numberOfParticipants) ? (accumulatedDisconnected + numberOfParticipants - j) : (accumulatedDisconnected); diff --git a/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/OpenViduTestAppE2eTest.java b/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/OpenViduTestAppE2eTest.java index b067323abf..59f9191b71 100644 --- a/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/OpenViduTestAppE2eTest.java +++ b/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/OpenViduTestAppE2eTest.java @@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit; import java.util.function.BiFunction; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -57,6 +58,11 @@ protected void setupEach() { this.closeAllRooms(LK); } + @AfterEach() + protected void finishEach() { + this.closeAllRooms(LK); + } + @Test @DisplayName("One2One Chrome") void oneToOneChrome() throws Exception { @@ -86,13 +92,18 @@ private void oneToOneAux(OpenViduTestappUser user) throws Exception { user.getDriver().findElement(By.id("one2one-btn")).click(); user.getEventManager().waitUntilEventReaches("signalConnected", "RoomEvent", 2); user.getEventManager().waitUntilEventReaches("connected", "RoomEvent", 2); + user.getEventManager().waitUntilEventReaches("connectionStateChanged", "RoomEvent", 2); user.getEventManager().waitUntilEventReaches("localTrackPublished", "RoomEvent", 4); user.getEventManager().waitUntilEventReaches("localTrackPublished", "ParticipantEvent", 4); + user.getEventManager().waitUntilEventReaches("localTrackSubscribed", "RoomEvent", 4); + user.getEventManager().waitUntilEventReaches("localTrackSubscribed", "ParticipantEvent", 4); user.getEventManager().waitUntilEventReaches("trackSubscribed", "RoomEvent", 4); user.getEventManager().waitUntilEventReaches("trackSubscribed", "ParticipantEvent", 4); user.getEventManager().waitUntilEventReaches("trackSubscriptionStatusChanged", "RoomEvent", 8); - user.getEventManager().waitUntilEventReaches("trackStreamStateChanged", "RoomEvent", 2); - user.getEventManager().waitUntilEventReaches("trackStreamStateChanged", "ParticipantEvent", 2); + // user.getEventManager().waitUntilEventReaches("trackStreamStateChanged", + // "RoomEvent", 2); + // user.getEventManager().waitUntilEventReaches("trackStreamStateChanged", + // "ParticipantEvent", 2); user.getWaiter().until(ExpectedConditions.numberOfElementsToBe(By.tagName("video"), 4)); user.getWaiter().until(ExpectedConditions.numberOfElementsToBe(By.tagName("audio"), 4)); @@ -130,6 +141,7 @@ void oneToOneOnlyAudioSession() throws Exception { user.getEventManager().waitUntilEventReaches("connected", "RoomEvent", 2); user.getEventManager().waitUntilEventReaches("localTrackPublished", "RoomEvent", 2); + user.getEventManager().waitUntilEventReaches("localTrackSubscribed", "RoomEvent", 2); user.getEventManager().waitUntilEventReaches("trackSubscribed", "RoomEvent", 2); final int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size(); @@ -165,6 +177,7 @@ void oneToOneOnlyVideoSession() throws Exception { user.getEventManager().waitUntilEventReaches("connected", "RoomEvent", 2); user.getEventManager().waitUntilEventReaches("localTrackPublished", "RoomEvent", 2); + user.getEventManager().waitUntilEventReaches("localTrackSubscribed", "RoomEvent", 2); user.getEventManager().waitUntilEventReaches("trackSubscribed", "RoomEvent", 2); final int numberOfAudios = user.getDriver().findElements(By.tagName("audio")).size(); @@ -198,6 +211,7 @@ void oneToManyVideoAudioSession() throws Exception { user.getEventManager().waitUntilEventReaches("signalConnected", "RoomEvent", USERS); user.getEventManager().waitUntilEventReaches("connected", "RoomEvent", USERS); user.getEventManager().waitUntilEventReaches("localTrackPublished", "RoomEvent", 2); + user.getEventManager().waitUntilEventReaches("localTrackSubscribed", "RoomEvent", 2); user.getEventManager().waitUntilEventReaches("trackSubscribed", "RoomEvent", (SUBSCRIBERS) * 2); user.getWaiter().until(ExpectedConditions.numberOfElementsToBe(By.tagName("video"), USERS)); @@ -233,6 +247,7 @@ void manyToManyVideoAudioSession() throws Exception { user.getEventManager().waitUntilEventReaches("signalConnected", "RoomEvent", 4); user.getEventManager().waitUntilEventReaches("connected", "RoomEvent", 4); user.getEventManager().waitUntilEventReaches("localTrackPublished", "RoomEvent", 8); + user.getEventManager().waitUntilEventReaches("localTrackSubscribed", "RoomEvent", 8); user.getEventManager().waitUntilEventReaches("trackSubscribed", "RoomEvent", 24); user.getWaiter().until(ExpectedConditions.numberOfElementsToBe(By.tagName("video"), 16)); @@ -271,8 +286,7 @@ void massiveSessionTest() throws Exception { user.getEventManager().waitUntilEventReaches("signalConnected", "RoomEvent", NUMBER_OF_USERS); user.getEventManager().waitUntilEventReaches("connected", "RoomEvent", NUMBER_OF_USERS); user.getEventManager().waitUntilEventReaches("localTrackPublished", "RoomEvent", NUMBER_OF_USERS * 2); - user.getEventManager().waitUntilEventReaches("trackPublished", "RoomEvent", - (NUMBER_OF_USERS) * (NUMBER_OF_USERS - 1) * 2); + user.getEventManager().waitUntilEventReaches("localTrackSubscribed", "RoomEvent", NUMBER_OF_USERS * 2); user.getEventManager().waitUntilEventReaches("trackSubscribed", "RoomEvent", (NUMBER_OF_USERS) * (NUMBER_OF_USERS - 1) * 2); @@ -315,8 +329,10 @@ public void uncaughtException(Thread th, Throwable ex) { user.getEventManager().waitUntilEventReaches("signalConnected", "RoomEvent", 1, 100, true); user.getEventManager().waitUntilEventReaches("connected", "RoomEvent", 1); user.getEventManager().waitUntilEventReaches("localTrackPublished", "RoomEvent", 2); + user.getEventManager().waitUntilEventReaches("localTrackSubscribed", "RoomEvent", 2); user.getEventManager().waitUntilEventReaches("trackSubscribed", "RoomEvent", 4); - user.getEventManager().waitUntilEventReaches("trackStreamStateChanged", "RoomEvent", 2); + // user.getEventManager().waitUntilEventReaches("trackStreamStateChanged", + // "RoomEvent", 2); user.getWaiter().until(ExpectedConditions.numberOfElementsToBe(By.tagName("video"), 3)); user.getWaiter().until(ExpectedConditions.numberOfElementsToBe(By.tagName("audio"), 3)); diff --git a/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.ts b/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.ts index e49a575103..1a9f3dbd2b 100644 --- a/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.ts +++ b/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.ts @@ -982,6 +982,29 @@ export class OpenviduInstanceComponent { ); } } + + if ( + firstTime || + this.roomEvents.get(RoomEvent.LocalTrackSubscribed) !== + oldValues.get(RoomEvent.LocalTrackSubscribed) + ) { + this.room?.removeAllListeners(RoomEvent.LocalTrackSubscribed); + if (this.roomEvents.get(RoomEvent.LocalTrackSubscribed)) { + this.room!.on( + RoomEvent.LocalTrackSubscribed, + ( + publication: LocalTrackPublication, + participant: LocalParticipant + ) => { + this.updateEventList( + RoomEvent.LocalTrackSubscribed, + { publication, participant }, + `${publication.source}` + ); + } + ); + } + } } updateEventList( diff --git a/openvidu-testapp/src/app/components/participant/participant.component.ts b/openvidu-testapp/src/app/components/participant/participant.component.ts index bc06093c92..caa2236051 100644 --- a/openvidu-testapp/src/app/components/participant/participant.component.ts +++ b/openvidu-testapp/src/app/components/participant/participant.component.ts @@ -335,7 +335,12 @@ export class ParticipantComponent { ) .on(ParticipantEvent.IsSpeakingChanged, (speaking: boolean) => { - // this.updateEventList(ParticipantEvent.IsSpeakingChanged, 'ParticipantEvent', { speaking }, `${speaking}`); + this.updateEventList( + ParticipantEvent.IsSpeakingChanged, + 'ParticipantEvent', + { speaking }, + `${speaking}` + ); }) .on( @@ -416,6 +421,18 @@ export class ParticipantComponent { `${publication.source}: ${status}` ); } + ) + + .on( + ParticipantEvent.LocalTrackSubscribed, + (trackPublication: LocalTrackPublication) => { + this.updateEventList( + ParticipantEvent.LocalTrackSubscribed, + 'ParticipantEvent', + { trackPublication }, + trackPublication.source + ); + } ); } diff --git a/openvidu-testapp/src/app/components/test-scenarios/test-scenarios.component.ts b/openvidu-testapp/src/app/components/test-scenarios/test-scenarios.component.ts index d61e7a24f9..9ab863df1c 100644 --- a/openvidu-testapp/src/app/components/test-scenarios/test-scenarios.component.ts +++ b/openvidu-testapp/src/app/components/test-scenarios/test-scenarios.component.ts @@ -233,6 +233,10 @@ export class TestScenariosComponent implements OnInit, OnDestroy { this.updateEventList(RoomEvent.LocalTrackPublished); }); + room.on(RoomEvent.LocalTrackSubscribed, () => { + this.updateEventList(RoomEvent.LocalTrackSubscribed); + }); + room.on(RoomEvent.TrackSubscribed, () => { this.updateEventList(RoomEvent.TrackSubscribed); });