openvidu-test-e2e: browser event polling thread reset method

pull/550/head
pabloFuente 2020-10-03 14:32:15 +02:00
parent a48778ba91
commit 7e75a6568a
3 changed files with 35 additions and 9 deletions

View File

@ -51,7 +51,7 @@ public class ChromeUser extends BrowserUser {
options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.IGNORE);
options.addArguments("--disable-infobars");
options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"});
options.setExperimentalOption("excludeSwitches", new String[] { "enable-automation" });
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.media_stream_mic", 1);
@ -84,6 +84,9 @@ public class ChromeUser extends BrowserUser {
// This flag selects the entire screen as video source when screen sharing
options.addArguments("--auto-select-desktop-capture-source=Entire screen");
// Background Chrome
// options.addArguments("--headless");
if (runningAsRoot) {
options.addArguments("--no-sandbox");
}

View File

@ -83,6 +83,7 @@ public class OpenViduEventManager {
private Map<String, AtomicInteger> eventNumbers;
private Map<String, CountDownLatch> eventCountdowns;
private AtomicBoolean isInterrupted = new AtomicBoolean(false);
private CountDownLatch pollingLatch = new CountDownLatch(1);
private int timeOfWaitInSeconds;
public OpenViduEventManager(WebDriver driver, int timeOfWaitInSeconds) {
@ -130,20 +131,21 @@ public class OpenViduEventManager {
e.printStackTrace();
}
}
log.info("Polling thread is now interrupted!");
this.pollingLatch.countDown();
});
this.pollingThread.setUncaughtExceptionHandler(h);
this.pollingThread.start();
}
public void stopPolling(boolean stopThread) {
this.eventCallbacks.clear();
this.eventCountdowns.clear();
this.eventNumbers.clear();
if (stopThread) {
this.isInterrupted.set(true);
this.pollingThread.interrupt();
}
this.eventCallbacks.clear();
this.eventCountdowns.clear();
this.eventNumbers.clear();
}
public void on(String eventName, Consumer<JsonObject> callback) {
@ -186,6 +188,26 @@ public class OpenViduEventManager {
this.setCountDown(eventName, new CountDownLatch(0));
}
public synchronized void clearAllCurrentEvents() {
this.eventNumbers.keySet().forEach(eventName -> {
this.clearCurrentEvents(eventName);
});
}
public void resetEventThread() throws InterruptedException {
this.stopPolling(true);
this.pollingLatch.await();
this.execService.shutdownNow();
this.execService.awaitTermination(10, TimeUnit.SECONDS);
this.execService = Executors.newCachedThreadPool();
this.stopPolling(false);
this.clearAllCurrentEvents();
this.isInterrupted.set(false);
this.pollingLatch = new CountDownLatch(1);
this.eventQueue.clear();
this.startPolling();
}
public boolean assertMediaTracks(WebElement videoElement, boolean audioTransmission, boolean videoTransmission,
String parentSelector) {
return this.assertMediaTracks(Collections.singleton(videoElement), audioTransmission, videoTransmission,

View File

@ -3068,13 +3068,14 @@ public class OpenViduTestAppE2eTest {
}
Thread.sleep(500);
user.getEventManager().resetEventThread();
user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .join-btn")).sendKeys(Keys.ENTER);
user.getEventManager().waitUntilEventReaches("connectionCreated", 5);
user.getEventManager().waitUntilEventReaches("accessAllowed", 3);
user.getEventManager().waitUntilEventReaches("streamCreated", 5);
user.getEventManager().waitUntilEventReaches("streamPlaying", 5);
user.getEventManager().waitUntilEventReaches("connectionCreated", 1);
user.getEventManager().waitUntilEventReaches("accessAllowed", 1);
user.getEventManager().waitUntilEventReaches("streamCreated", 1);
user.getEventManager().waitUntilEventReaches("streamPlaying", 1);
// connectionId should be equal to the one brought by the token
Assert.assertEquals("Wrong connectionId", tokenBConnectionId,