openvidu-test-e2e: relax synchronization of browser launch

pull/884/merge
pabloFuente 2026-06-03 12:09:32 +02:00
parent c67e820e93
commit 09cf208f73
2 changed files with 26 additions and 21 deletions

View File

@ -14,10 +14,10 @@ import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import javax.net.ssl.SSLContext;
@ -116,8 +116,8 @@ public class OpenViduTestE2e {
protected static final CommandLineExecutor commandLine = new CommandLineExecutor();
protected static final String RECORDING_IMAGE = "openvidu/openvidu-recording";
protected Collection<BrowserUser> browserUsers = new HashSet<>();
protected static Collection<GenericContainer<?>> containers = new HashSet<>();
protected Collection<BrowserUser> browserUsers = ConcurrentHashMap.newKeySet();
protected static Collection<GenericContainer<?>> containers = ConcurrentHashMap.newKeySet();
protected static RoomServiceClient LK;
protected static IngressServiceClient LK_INGRESS;
@ -512,18 +512,22 @@ public class OpenViduTestE2e {
return browserUser;
}
private static synchronized boolean setupBrowserAux(BrowserNames browser, GenericContainer<?> container, boolean forceRestart) {
private static final Map<BrowserNames, Object> browserSetupLocks = new ConcurrentHashMap<>();
private static boolean setupBrowserAux(BrowserNames browser, GenericContainer<?> container, boolean forceRestart) {
if (isRemote(browser)) {
String dockerImage = container.getDockerImageName();
String ps = commandLine.executeCommand("docker ps | grep " + dockerImage, 30);
boolean containerAlreadyRunning = container.isRunning() || !ps.isBlank();
if (forceRestart && containerAlreadyRunning) {
container.stop();
}
if (!containerAlreadyRunning) {
container.start();
containers.add(container);
return true;
synchronized (browserSetupLocks.computeIfAbsent(browser, b -> new Object())) {
String dockerImage = container.getDockerImageName();
String ps = commandLine.executeCommand("docker ps | grep " + dockerImage, 30);
boolean containerAlreadyRunning = container.isRunning() || !ps.isBlank();
if (forceRestart && containerAlreadyRunning) {
container.stop();
}
if (!containerAlreadyRunning) {
container.start();
containers.add(container);
return true;
}
}
}
return false;

View File

@ -1338,7 +1338,7 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
final java.util.concurrent.atomic.AtomicLong subscriber1920AtMs = new java.util.concurrent.atomic.AtomicLong(
-1);
final String publisherBrowser = subscriberBrowser == "chromeTwoInstances" ? "chromeTwoInstances" : "chrome";
final String publisherBrowser = "chromeTwoInstances".equals(subscriberBrowser) ? "chromeTwoInstances" : "chrome";
Future<?> task1 = executor.submit(() -> {
try {
@ -3590,13 +3590,14 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
Assertions.fail(errMsg);
}
} finally {
// Close dialog
user.getWaiter().until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#close-dialog-btn")));
this.waitForBackdropAndClick(user, "#close-dialog-btn");
// Best-effort close of the info dialog
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
if (!user.getDriver().findElements(By.cssSelector("#close-dialog-btn")).isEmpty()) {
this.waitForBackdropAndClick(user, "#close-dialog-btn");
Thread.sleep(500);
}
} catch (Exception e) {
log.warn("Best-effort info-dialog close failed (ignored): {}", e.getMessage());
}
}
}