mirror of https://github.com/OpenVidu/openvidu.git
openvidu-test-e2e: obtain broadcast container IP dynamically
parent
a1b7081f9d
commit
13651e8a76
|
@ -6,6 +6,7 @@ import java.io.File;
|
|||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
@ -24,6 +25,7 @@ import java.util.concurrent.TimeoutException;
|
|||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.validator.routines.InetAddressValidator;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.openqa.selenium.By;
|
||||
|
@ -85,7 +87,6 @@ public class OpenViduTestE2e {
|
|||
protected static String OPENVIDU_PRO_SPEECH_TO_TEXT = "vosk";
|
||||
protected static String DOCKERHUB_PRIVATE_REGISTRY_PASSWORD = "not_valid";
|
||||
protected static String EXTERNAL_CUSTOM_LAYOUT_PARAMS = "sessionId,CUSTOM_LAYOUT_SESSION,secret,MY_SECRET";
|
||||
protected static String BROADCAST_IP = "172.17.0.1";
|
||||
|
||||
protected static String AWS_REGION = "fakeRegion";
|
||||
protected static String AWS_ACCESS_KEY_ID = "fakeKey";
|
||||
|
@ -358,12 +359,6 @@ public class OpenViduTestE2e {
|
|||
OPENVIDU_DEPLOYMENT = openviduDeployment;
|
||||
}
|
||||
log.info("Using URL {} to connect to OpenVidu deployment", OPENVIDU_DEPLOYMENT);
|
||||
|
||||
String broadcastIp = System.getProperty("BROADCAST_IP");
|
||||
if (broadcastIp != null) {
|
||||
BROADCAST_IP = broadcastIp;
|
||||
}
|
||||
log.info("Using IP {} to broadcast", BROADCAST_IP);
|
||||
}
|
||||
|
||||
protected BrowserUser setupBrowser(String browser) throws Exception {
|
||||
|
@ -865,12 +860,17 @@ public class OpenViduTestE2e {
|
|||
}
|
||||
}
|
||||
|
||||
// https://github.com/tiangolo/nginx-rtmp-docker
|
||||
protected static void startRtmpServer() throws IOException {
|
||||
/**
|
||||
* https://github.com/tiangolo/nginx-rtmp-docker
|
||||
*
|
||||
* @return The IP address of the Docker container
|
||||
*/
|
||||
protected static String startRtmpServer() throws IOException, TimeoutException {
|
||||
File file = writeRtmpServerConfigInFile();
|
||||
String dockerRunCommand = "docker run -d --name broadcast-nginx -p 1935:1935 -v " + file.getAbsolutePath()
|
||||
+ ":/etc/nginx/nginx.conf tiangolo/nginx-rtmp";
|
||||
commandLine.executeCommand(dockerRunCommand, 10);
|
||||
return waitForContainerIpAddress("broadcast-nginx", 10);
|
||||
}
|
||||
|
||||
protected static void stopRtmpServer() {
|
||||
|
@ -878,6 +878,21 @@ public class OpenViduTestE2e {
|
|||
commandLine.executeCommand(dockerRemoveCommand, 10);
|
||||
}
|
||||
|
||||
protected static String waitForContainerIpAddress(String containerNameOrId, int secondsTimeout)
|
||||
throws TimeoutException, UnknownHostException {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long maxTime = currentTime + (secondsTimeout * 1000);
|
||||
while (System.currentTimeMillis() < maxTime) {
|
||||
String ip = commandLine.executeCommand(
|
||||
"docker container inspect -f '{{ .NetworkSettings.IPAddress }}' " + containerNameOrId, 3);
|
||||
InetAddressValidator validator = InetAddressValidator.getInstance();
|
||||
if (validator.isValid(ip)) {
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
throw new TimeoutException();
|
||||
}
|
||||
|
||||
private static File writeRtmpServerConfigInFile() throws IOException {
|
||||
String newLine = System.getProperty("line.separator");
|
||||
// @formatter:off
|
||||
|
|
|
@ -230,7 +230,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
io.openvidu.test.browsers.utils.webhook.CustomWebhook.main(new String[0], initLatch);
|
||||
|
||||
try {
|
||||
startRtmpServer();
|
||||
String BROADCAST_IP = startRtmpServer();
|
||||
|
||||
if (!initLatch.await(30, TimeUnit.SECONDS)) {
|
||||
Assertions.fail("Timeout waiting for webhook springboot app to start");
|
||||
|
@ -262,14 +262,14 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
OpenViduTestappUser user = setupBrowserAndConnectToOpenViduTestapp("chrome");
|
||||
|
||||
// unsubscribe: webrtcConnectionDestroyed
|
||||
this.connectTwoUsers(user, restClient, false, false, false);
|
||||
this.connectTwoUsers(user, restClient, false, false, null);
|
||||
user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .sub-btn")).click();
|
||||
Assertions.assertEquals("unsubscribe",
|
||||
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString());
|
||||
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
|
||||
|
||||
// unpublish: webrtcConnectionDestroyed
|
||||
this.connectTwoUsers(user, restClient, false, false, false);
|
||||
this.connectTwoUsers(user, restClient, false, false, null);
|
||||
user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .pub-btn")).click();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
Assertions.assertEquals("unpublish",
|
||||
|
@ -280,7 +280,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
// disconnect: webrtcConnectionDestroyed, participantLeft (and subsequent
|
||||
// lastParticipantLeft triggered events for sessionDestroyed,
|
||||
// recordingStatusChanged, broadcastStopped)
|
||||
this.connectTwoUsers(user, restClient, false, true, true);
|
||||
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
|
||||
// First user out
|
||||
user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .leave-btn")).click();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
@ -306,7 +306,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
|
||||
|
||||
// forceUnpublishByUser: webrtcConnectionDestroyed
|
||||
this.connectTwoUsers(user, restClient, true, false, false);
|
||||
this.connectTwoUsers(user, restClient, true, false, null);
|
||||
user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .force-unpub-btn")).click();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
Assertions.assertEquals("forceUnpublishByUser",
|
||||
|
@ -315,7 +315,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
|
||||
|
||||
// forceUnpublishByServer: webrtcConnectionDestroyed
|
||||
this.connectTwoUsers(user, restClient, false, false, false);
|
||||
this.connectTwoUsers(user, restClient, false, false, null);
|
||||
String streamId = restClient
|
||||
.rest(HttpMethod.GET, "/openvidu/api/sessions/TestSession", HttpURLConnection.HTTP_OK)
|
||||
.get("connections").getAsJsonObject().get("content").getAsJsonArray().asList().stream()
|
||||
|
@ -331,7 +331,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
|
||||
|
||||
// forceDisconnectByUser: webrtcConnectionDestroyed, participantLeft
|
||||
this.connectTwoUsers(user, restClient, true, false, false);
|
||||
this.connectTwoUsers(user, restClient, true, false, null);
|
||||
user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .force-disconnect-btn")).click();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Assertions.assertEquals("forceDisconnectByUser",
|
||||
|
@ -344,7 +344,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
// forceDisconnectByServer: webrtcConnectionDestroyed, participantLeft (and
|
||||
// subsequent lastParticipantLeft triggered events for sessionDestroyed,
|
||||
// recordingStatusChanged, broadcastStopped)
|
||||
this.connectTwoUsers(user, restClient, false, true, true);
|
||||
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
|
||||
String[] connectionIds = restClient
|
||||
.rest(HttpMethod.GET, "/openvidu/api/sessions/TestSession", HttpURLConnection.HTTP_OK)
|
||||
.get("connections").getAsJsonObject().get("content").getAsJsonArray().asList().stream()
|
||||
|
@ -377,7 +377,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
|
||||
// sessionClosedByServer: webrtcConnectionDestroyed, participantLeft,
|
||||
// sessionDestroyed, recordingStatusChanged, broadcastStopped
|
||||
this.connectTwoUsers(user, restClient, false, true, true);
|
||||
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
|
||||
restClient.rest(HttpMethod.DELETE, "/openvidu/api/sessions/TestSession",
|
||||
HttpURLConnection.HTTP_NO_CONTENT);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
@ -401,7 +401,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
// networkDisconnect: webrtcConnectionDestroyed, participantLeft (and
|
||||
// subsequent lastParticipantLeft triggered events for sessionDestroyed,
|
||||
// recordingStatusChanged, broadcastStopped)
|
||||
this.connectTwoUsers(user, restClient, false, true, true);
|
||||
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
|
||||
// First user out
|
||||
user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .network-drop-btn")).click();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
@ -428,7 +428,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
|
||||
// mediaServerDisconnect: webrtcConnectionDestroyed, participantLeft,
|
||||
// sessionDestroyed, recordingStatusChanged, broadcastStopped
|
||||
this.connectTwoUsers(user, restClient, false, true, true);
|
||||
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
|
||||
String mediaNodeId = restClient
|
||||
.rest(HttpMethod.GET, "/openvidu/api/media-nodes", HttpURLConnection.HTTP_OK).get("content")
|
||||
.getAsJsonArray().get(0).getAsJsonObject().get("id").getAsString();
|
||||
|
@ -457,7 +457,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
restartOpenViduServer(new HashMap<>(), true, HttpURLConnection.HTTP_OK);
|
||||
|
||||
// mediaServerReconnect: webrtcConnectionDestroyed, recordingStatusChanged
|
||||
this.connectTwoUsers(user, restClient, false, true, true);
|
||||
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
|
||||
String containerId = restClient
|
||||
.rest(HttpMethod.GET, "/openvidu/api/media-nodes", HttpURLConnection.HTTP_OK).get("content")
|
||||
.getAsJsonArray().get(0).getAsJsonObject().get("environmentId").getAsString();
|
||||
|
@ -474,7 +474,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
|
||||
// nodeCrashed: webrtcConnectionDestroyed, participantLeft, sessionDestroyed,
|
||||
// recordingStatusChanged, broadcastStopped
|
||||
this.connectTwoUsers(user, restClient, false, true, true);
|
||||
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
|
||||
containerId = restClient.rest(HttpMethod.GET, "/openvidu/api/media-nodes", HttpURLConnection.HTTP_OK)
|
||||
.get("content").getAsJsonArray().get(0).getAsJsonObject().get("environmentId").getAsString();
|
||||
MediaNodeDockerUtils.crashMediaNode(containerId);
|
||||
|
@ -507,7 +507,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
|
||||
// openviduServerStopped: webrtcConnectionDestroyed, participantLeft,
|
||||
// sessionDestroyed, recordingStatusChanged, broadcastStopped
|
||||
this.connectTwoUsers(user, restClient, false, true, true);
|
||||
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
|
||||
restartOpenViduServer(new HashMap<>(), true, HttpURLConnection.HTTP_OK);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Assertions.assertEquals("openviduServerStopped",
|
||||
|
@ -533,7 +533,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
// automaticStop: sessionDestroyed, recordingStatusChanged
|
||||
newConfig = Map.of("OPENVIDU_RECORDING_AUTOSTOP_TIMEOUT", 1);
|
||||
restartOpenViduServer(newConfig);
|
||||
this.connectTwoUsers(user, restClient, false, true, true);
|
||||
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
|
||||
user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .leave-btn")).click();
|
||||
user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .leave-btn")).click();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
@ -555,7 +555,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
|
||||
|
||||
// recordingStoppedByServer: recordingStatusChanged
|
||||
this.connectTwoUsers(user, restClient, false, true, true);
|
||||
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
|
||||
String recordingId = restClient
|
||||
.rest(HttpMethod.GET, "/openvidu/api/recordings", HttpURLConnection.HTTP_OK).get("items")
|
||||
.getAsJsonArray().asList().stream()
|
||||
|
@ -571,7 +571,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
|
||||
|
||||
// broadcastStoppedByServer: broadcastStopped
|
||||
this.connectTwoUsers(user, restClient, false, true, true);
|
||||
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
|
||||
restClient.rest(HttpMethod.POST, "/openvidu/api/broadcast/stop", "{'session':'TestSession'}",
|
||||
HttpURLConnection.HTTP_OK);
|
||||
Assertions.assertEquals("broadcastStoppedByServer",
|
||||
|
@ -1090,7 +1090,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
Assertions.assertTrue(connection.getNetworkCache() == null, "Wrong networkCache property");
|
||||
|
||||
try {
|
||||
startRtmpServer();
|
||||
String BROADCAST_IP = startRtmpServer();
|
||||
// Start broadcast
|
||||
try {
|
||||
OV.startBroadcast("NOT_EXISTS", "rtmp://" + BROADCAST_IP + "/live");
|
||||
|
@ -2810,7 +2810,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
log.info("Successfull broadcast Test");
|
||||
|
||||
try {
|
||||
startRtmpServer();
|
||||
String BROADCAST_IP = startRtmpServer();
|
||||
|
||||
OpenViduTestappUser user = setupBrowserAndConnectToOpenViduTestapp("chrome");
|
||||
user.getDriver().findElement(By.id("add-user-btn")).click();
|
||||
|
@ -2870,7 +2870,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
log.info("Wrong broadcast Test");
|
||||
|
||||
try {
|
||||
startRtmpServer();
|
||||
String BROADCAST_IP = startRtmpServer();
|
||||
|
||||
OpenViduTestappUser user = setupBrowserAndConnectToOpenViduTestapp("chrome");
|
||||
user.getDriver().findElement(By.id("add-user-btn")).click();
|
||||
|
@ -3211,7 +3211,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
}
|
||||
|
||||
private void connectTwoUsers(OpenViduTestappUser user, CustomHttpClient restClient, boolean firstUserIsModerator,
|
||||
boolean startRecording, boolean startBroadcast) throws Exception {
|
||||
boolean startRecording, String broadcastIp) throws Exception {
|
||||
this.closeAllSessions(OV);
|
||||
user.getDriver().findElement(By.id("remove-all-users-btn")).click();
|
||||
user.getEventManager().clearAllCurrentEvents();
|
||||
|
@ -3241,9 +3241,9 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
Assertions.assertEquals(Recording.Status.started.name(),
|
||||
CustomWebhook.waitForEvent("recordingStatusChanged", 3).get("status").getAsString());
|
||||
}
|
||||
if (startBroadcast) {
|
||||
if (broadcastIp != null) {
|
||||
restClient.rest(HttpMethod.POST, "/openvidu/api/broadcast/start",
|
||||
"{'session':'TestSession','broadcastUrl':'rtmp://" + BROADCAST_IP + "/live'}",
|
||||
"{'session':'TestSession','broadcastUrl':'rtmp://" + broadcastIp + "/live'}",
|
||||
HttpURLConnection.HTTP_OK);
|
||||
user.getEventManager().waitUntilEventReaches("broadcastStarted", 2);
|
||||
CustomWebhook.waitForEvent("broadcastStarted", 3);
|
||||
|
|
Loading…
Reference in New Issue