openvidu-test-e2e: wait for containers to be removed at @AfterEach

pull/669/head
pabloFuente 2021-11-12 15:35:29 +01:00
parent 73df3cc969
commit a281c5b2f9
5 changed files with 27 additions and 12 deletions

View File

@ -42,7 +42,7 @@ public class ChromeUser extends BrowserUser {
}
public ChromeUser(String userName, int timeOfWaitInSeconds, Path fakeVideoLocation) {
this(userName, timeOfWaitInSeconds, generateFakeVideoChromeOptions(fakeVideoLocation), false);
this(userName, timeOfWaitInSeconds, generateFakeVideoChromeOptions(fakeVideoLocation), true);
}
private ChromeUser(String userName, int timeOfWaitInSeconds, ChromeOptions options, boolean headless) {

View File

@ -19,15 +19,20 @@ package io.openvidu.test.browsers.utils;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.concurrent.TimeUnit;
public class CommandLineExecutor {
public String executeCommand(String command) {
public String executeCommand(String command, int secondsTimeout) {
String output = "";
Process p = null;
try {
p = Runtime.getRuntime().exec((new String[] { "/bin/sh", "-c", command }));
p.waitFor();
if (!p.waitFor(secondsTimeout, TimeUnit.SECONDS)) {
System.err.println("Command " + command + " did not completed in " + secondsTimeout + " seconds");
p.destroyForcibly();
return output;
}
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = br.readLine()) != null) {

View File

@ -152,7 +152,7 @@ public class MultimediaFileMetadata {
private JsonObject executeFfprobeCommand(String filePath) {
log.info("Running ffprobe command on '{}'", filePath);
String cmd = "ffprobe -v quiet -print_format json -show_format -show_streams " + filePath;
return JsonParser.parseString(this.executer.executeCommand(cmd)).getAsJsonObject();
return JsonParser.parseString(this.executer.executeCommand(cmd, 60)).getAsJsonObject();
}
private void fixWebmFile(String filePath) throws IOException {
@ -162,7 +162,7 @@ public class MultimediaFileMetadata {
pathCopy = java.nio.file.Files.move(source, source.resolveSibling("COPY." + extension)).toString();
log.warn("Fixing file '{}' with ffmpeg", filePath);
String cmd = "ffmpeg -i " + pathCopy + " -vcodec copy -acodec copy " + filePath;
this.executer.executeCommand(cmd);
this.executer.executeCommand(cmd, 60);
new File(pathCopy).delete();
}

View File

@ -8,6 +8,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
@ -109,7 +110,7 @@ public class OpenViduTestE2e {
protected RecordingUtils recordingUtils = new RecordingUtils();
protected static void checkFfmpegInstallation() {
String ffmpegOutput = commandLine.executeCommand("which ffmpeg");
String ffmpegOutput = commandLine.executeCommand("which ffmpeg", 60);
if (ffmpegOutput == null || ffmpegOutput.isEmpty()) {
log.error("ffmpeg package is not installed in the host machine");
Assert.fail();
@ -330,7 +331,7 @@ public class OpenViduTestE2e {
browserUser = new ChromeUser("TestUser", 50, "OpenVidu TestApp");
break;
case "chromeAlternateFakeVideo":
container = chromeContainer("selenium/standalone-chrome:" + CHROME_VERSION, 2147483648L, 1, false);
container = chromeContainer("selenium/standalone-chrome:" + CHROME_VERSION, 2147483648L, 1, true);
setupBrowserAux(BrowserNames.CHROME, container, false);
browserUser = new ChromeUser("TestUser", 50, Paths.get("/opt/openvidu/barcode.y4m"));
break;
@ -464,11 +465,19 @@ public class OpenViduTestE2e {
}
// Stop and remove all browser containers if necessary
Iterator<GenericContainer<?>> it2 = containers.iterator();
List<String> waitUntilContainerIsRemovedCommands = new ArrayList<>();
containers.forEach(c -> {
waitUntilContainerIsRemovedCommands
.add("while docker inspect " + c.getContainerId() + " >/dev/null 2>&1; do sleep 1; done");
});
while (it2.hasNext()) {
GenericContainer<?> c = it2.next();
stopContainerIfPossible(c);
it2.remove();
}
waitUntilContainerIsRemovedCommands.forEach(command -> {
commandLine.executeCommand(command, 30);
});
// Reset REST client
OV = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET);
}
@ -549,7 +558,7 @@ public class OpenViduTestE2e {
log.error("Unrecognized MEDIA_SERVER_IMAGE: {}", MEDIA_SERVER_IMAGE);
System.exit(1);
}
commandLine.executeCommand(command);
commandLine.executeCommand(command, 60);
if (waitUntilKurentoClientReconnection) {
try {
Thread.sleep(5000);
@ -572,7 +581,7 @@ public class OpenViduTestE2e {
log.error("Unrecognized MEDIA_SERVER_IMAGE: {}", MEDIA_SERVER_IMAGE);
System.exit(1);
}
commandLine.executeCommand(dockerRemoveCmd.replaceFirst("GREP_PARAMETER", grep));
commandLine.executeCommand(dockerRemoveCmd.replaceFirst("GREP_PARAMETER", grep), 60);
if (waitUntilNodeCrashedEvent) {
try {
Thread.sleep(4000);
@ -583,13 +592,13 @@ public class OpenViduTestE2e {
}
protected void checkDockerContainerRunning(String imageName, int amount) {
int number = Integer.parseInt(commandLine.executeCommand("docker ps | grep " + imageName + " | wc -l"));
int number = Integer.parseInt(commandLine.executeCommand("docker ps | grep " + imageName + " | wc -l", 60));
Assert.assertEquals("Wrong number of Docker containers for image " + imageName + " running", amount, number);
}
protected void removeAllRecordingContiners() {
commandLine.executeCommand("docker ps -a | awk '{ print $1,$2 }' | grep " + RECORDING_IMAGE
+ " | awk '{print $1 }' | xargs -I {} docker rm -f {}");
+ " | awk '{print $1 }' | xargs -I {} docker rm -f {}", 60);
}
protected String mergeJson(String json, String newProperties, String[] removeProperties) {

View File

@ -78,6 +78,7 @@ import io.openvidu.java.client.RecordingProperties;
import io.openvidu.java.client.Session;
import io.openvidu.java.client.SessionProperties;
import io.openvidu.java.client.VideoCodec;
import io.openvidu.test.browsers.BrowserUser;
import io.openvidu.test.browsers.utils.BrowserNames;
import io.openvidu.test.browsers.utils.CustomHttpClient;
import io.openvidu.test.browsers.utils.RecordingUtils;
@ -165,7 +166,7 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
@Disabled
void oneToOneIonicAndroid() throws Exception {
long initTime = System.currentTimeMillis();
OpenViduTestappUser user = setupBrowserAndConnectToOpenViduTestapp("androidApp");
BrowserUser user = setupBrowser("androidApp");
log.info("Android emulator ready after {} seconds", (System.currentTimeMillis() - initTime) / 1000);
log.info("One2One Ionic Android");