Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
  • Loading branch information
VietND96 committed Oct 24, 2024
1 parent fca3b20 commit 46a9894
Showing 1 changed file with 45 additions and 9 deletions.
54 changes: 45 additions & 9 deletions java/test/org/openqa/selenium/grid/router/StressTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.NoSuchSessionException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.grid.config.MapConfig;
import org.openqa.selenium.grid.config.MemoizedConfig;
import org.openqa.selenium.grid.config.TomlConfig;
Expand Down Expand Up @@ -73,7 +75,9 @@ public void setupServers() {
+ "driver-implementation = "
+ browser.displayName()
+ "\n"
+ "session-timeout = 15")));
+ "session-timeout = 15"
+ "\n"
+ "enable-managed-downloads = true")));
tearDowns.add(deployment);

server = deployment.getServer();
Expand Down Expand Up @@ -114,7 +118,10 @@ void multipleSimultaneousSessions() throws Exception {
try {
WebDriver driver =
RemoteWebDriver.builder()
.oneOf(browser.getCapabilities())
.oneOf(
browser
.getCapabilities()
.merge(new MutableCapabilities(Map.of("se:downloadsEnabled", true))))
.address(server.getUrl())
.build();

Expand All @@ -134,13 +141,42 @@ void multipleSimultaneousSessions() throws Exception {
}

@Test
void testStopTimedOutSession() throws Exception {
void multipleSimultaneousSessionsTimedOut() throws Exception {
assertThat(server.isStarted()).isTrue();
WebDriver driver =
RemoteWebDriver.builder().oneOf(browser.getCapabilities()).address(server.getUrl()).build();
driver.get(appServer.getUrl().toString());
Thread.sleep(15000);
NoSuchSessionException exception = assertThrows(NoSuchSessionException.class, driver::getTitle);
assertTrue(exception.getMessage().startsWith("Cannot find session with id:"));

CompletableFuture<?>[] futures = new CompletableFuture<?>[10];
for (int i = 0; i < futures.length; i++) {
CompletableFuture<Object> future = new CompletableFuture<>();
futures[i] = future;

executor.submit(
() -> {
try {
WebDriver driver =
RemoteWebDriver.builder()
.oneOf(browser.getCapabilities())
.address(server.getUrl())
.build();
driver.get(appServer.getUrl().toString());
Thread.sleep(15000);
NoSuchSessionException exception =
assertThrows(NoSuchSessionException.class, driver::getTitle);
assertTrue(exception.getMessage().startsWith("Cannot find session with id:"));
WebDriverException webDriverException =
assertThrows(
WebDriverException.class,
() -> ((RemoteWebDriver) driver).getDownloadableFiles());
assertTrue(
webDriverException
.getMessage()
.startsWith("Cannot find downloads file system for session id:"));
future.complete(true);
} catch (Exception e) {
future.completeExceptionally(e);
}
});
}

CompletableFuture.allOf(futures).get(4, MINUTES);
}
}

0 comments on commit 46a9894

Please sign in to comment.