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 { public void resetEventThread(boolean clearData) throws InterruptedException {
this.stopPolling(true, true); this.stopPolling(true, clearData);
this.pollingLatch.await(); this.pollingLatch.await();
this.execService.shutdownNow(); this.execService.shutdownNow();
this.execService.awaitTermination(10, TimeUnit.SECONDS); this.execService.awaitTermination(10, TimeUnit.SECONDS);
this.execService = Executors.newCachedThreadPool(); this.execService = Executors.newCachedThreadPool();
this.stopPolling(false, true); this.stopPolling(false, clearData);
this.clearAllCurrentEvents(); if (clearData) {
this.clearAllCurrentEvents();
}
this.isInterrupted.set(false); this.isInterrupted.set(false);
this.pollingLatch = new CountDownLatch(1); this.pollingLatch = new CountDownLatch(1);
this.eventQueue.clear(); if (clearData) {
this.eventQueue.clear();
}
this.startPolling(); this.startPolling();
} }

View File

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

View File

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

View File

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