openvidu-test-e2e: reset event thread on alert opened

pull/672/head
pabloFuente 2021-11-15 12:20:57 +01:00
parent e60ac50d26
commit 13317a888d
4 changed files with 44 additions and 22 deletions

View File

@ -197,17 +197,21 @@ public class OpenViduEventManager {
});
}
public void resetEventThread() throws InterruptedException {
this.stopPolling(true, true);
public void resetEventThread(boolean clearData) throws InterruptedException {
this.stopPolling(true, clearData);
this.pollingLatch.await();
this.execService.shutdownNow();
this.execService.awaitTermination(10, TimeUnit.SECONDS);
this.execService = Executors.newCachedThreadPool();
this.stopPolling(false, true);
this.stopPolling(false, clearData);
if (clearData) {
this.clearAllCurrentEvents();
}
this.isInterrupted.set(false);
this.pollingLatch = new CountDownLatch(1);
if (clearData) {
this.eventQueue.clear();
}
this.startPolling();
}

View File

@ -403,10 +403,13 @@ public class OpenViduTestE2e {
private void setupBrowserAux(BrowserNames browser, GenericContainer<?> container, boolean forceRestart) {
if (isRemote(browser)) {
if (forceRestart && container.isRunning()) {
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 (!container.isRunning()) {
if (!containerAlreadyRunning) {
container.start();
containers.add(container);
}

View File

@ -335,6 +335,8 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
alert.accept();
} catch (Exception e) {
Assert.fail("Alert exception");
} finally {
user.getEventManager().resetEventThread(false);
}
Thread.sleep(500);
@ -471,7 +473,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
Assert.assertEquals("Wrong data in Connection object", "MY_SERVER_PRO_DATA", connection.getServerData());
Assert.assertEquals("Wrong status in Connection object", "active", connection.getStatus());
user.getEventManager().resetEventThread();
user.getEventManager().resetEventThread(true);
user.getWaiter().until(ExpectedConditions.elementToBeClickable(By.cssSelector(".republish-error-btn")));
user.getDriver().findElement(By.cssSelector(".republish-error-btn")).click();

View File

@ -3300,10 +3300,12 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
alert.accept();
} catch (Exception e) {
Assert.fail("Alert exception");
} finally {
user.getEventManager().resetEventThread(false);
}
Thread.sleep(500);
user.getEventManager().resetEventThread();
user.getEventManager().resetEventThread(true);
user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .join-btn")).sendKeys(Keys.ENTER);
@ -3481,13 +3483,18 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
user.getDriver().findElement(By.className("subscribe-checkbox")).click();
user.getDriver().findElement(By.className("join-btn")).click();
try {
user.getWaiter().until(ExpectedConditions.alertIsPresent());
Alert alert = user.getDriver().switchTo().alert();
final String alertMessage = "Error connecting to the session: There is no available Media Node where to initialize session 'TestSession'. Code: 204";
Assert.assertTrue("Alert message wrong. Expected to contain: \"" + alertMessage + "\". Actual message: \""
+ alert.getText() + "\"", alert.getText().contains(alertMessage));
Assert.assertTrue("Alert message wrong. Expected to contain: \"" + alertMessage
+ "\". Actual message: \"" + alert.getText() + "\"", alert.getText().contains(alertMessage));
alert.accept();
} catch (Exception e) {
Assert.fail("Alert exception");
} finally {
user.getEventManager().resetEventThread(false);
}
OV.fetch();
sessions = OV.getActiveSessions();
@ -3520,7 +3527,7 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
this.stopMediaServer(false);
this.startMediaServer(true);
user.getEventManager().resetEventThread();
user.getEventManager().resetEventThread(true);
user.getDriver().findElement(By.id("add-user-btn")).click();
user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .join-btn")).click();
user.getEventManager().waitUntilEventReaches("streamCreated", 2);
@ -4728,11 +4735,17 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
} else {
// If transcoding not allowed it should return an alert with error
user.getDriver().findElements(By.className("join-btn")).forEach(el -> el.sendKeys(Keys.ENTER));
try {
user.getWaiter().until(ExpectedConditions.alertIsPresent());
Alert alert = user.getDriver().switchTo().alert();
Assert.assertTrue("Alert does not contain expected text",
alert.getText().contains("Error forcing codec: '" + codec.name() + "'"));
alert.accept();
} catch (Exception e) {
Assert.fail("Alert exception");
} finally {
user.getEventManager().resetEventThread(false);
}
}
restClient.rest(HttpMethod.DELETE, "/openvidu/api/sessions/" + sessionName, HttpStatus.SC_NO_CONTENT);