Skip to content

Commit

Permalink
openvidu-test-e2e: improved e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloFuente committed Sep 30, 2024
1 parent 71598c2 commit e307af2
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
}
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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<List<Room>> response = client.listRooms().execute();
if (response.isSuccessful()) {
List<Room> 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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -416,6 +421,18 @@ export class ParticipantComponent {
`${publication.source}: ${status}`
);
}
)

.on(
ParticipantEvent.LocalTrackSubscribed,
(trackPublication: LocalTrackPublication) => {
this.updateEventList(
ParticipantEvent.LocalTrackSubscribed,
'ParticipantEvent',
{ trackPublication },
trackPublication.source
);
}
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit e307af2

Please sign in to comment.