Skip to content

Commit

Permalink
Fixed tests and race condition potential
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Oct 22, 2024
1 parent b0f3cd9 commit a7a838a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 84 deletions.
26 changes: 14 additions & 12 deletions java/src/org/openqa/selenium/grid/node/local/LocalNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -944,18 +944,20 @@ public void drain() {
}

private void checkSessionCount() {
if (this.drainAfterSessions.get()) {
int remainingSessions = this.sessionCount.decrementAndGet();
LOG.log(
Debug.getDebugLogLevel(),
"{0} remaining sessions before draining Node",
remainingSessions);
if (remainingSessions <= 0) {
LOG.info(
String.format(
"Draining Node, configured sessions value (%s) has been reached.",
this.configuredSessionCount));
drain();
synchronized (sessionCount) {
if (this.drainAfterSessions.get()) {
int remainingSessions = this.sessionCount.decrementAndGet();
LOG.log(
Debug.getDebugLogLevel(),
"{0} remaining sessions before draining Node",
remainingSessions);
if (remainingSessions <= 0) {
LOG.info(
String.format(
"Draining Node, configured sessions value (%s) has been reached.",
this.configuredSessionCount));
drain();
}
}
}
}
Expand Down
20 changes: 0 additions & 20 deletions java/test/org/openqa/selenium/grid/e2e/BUILD.bazel

This file was deleted.

51 changes: 0 additions & 51 deletions java/test/org/openqa/selenium/grid/e2e/SessionTimeoutTest.java

This file was deleted.

21 changes: 20 additions & 1 deletion java/test/org/openqa/selenium/grid/router/StressTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.concurrent.TimeUnit.MINUTES;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.StringReader;
import java.util.LinkedList;
Expand All @@ -33,6 +35,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchSessionException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.grid.config.MapConfig;
import org.openqa.selenium.grid.config.MemoizedConfig;
Expand Down Expand Up @@ -65,7 +68,12 @@ public void setupServers() {
DeploymentTypes.DISTRIBUTED.start(
browser.getCapabilities(),
new TomlConfig(
new StringReader("[node]\n" + "driver-implementation = " + browser.displayName())));
new StringReader(
"[node]\n"
+ "driver-implementation = "
+ browser.displayName()
+ "\n"
+ "session-timeout = 15")));
tearDowns.add(deployment);

server = deployment.getServer();
Expand Down Expand Up @@ -124,4 +132,15 @@ void multipleSimultaneousSessions() throws Exception {

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

@Test
void testStopTimedOutSession() 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:"));
}
}

0 comments on commit a7a838a

Please sign in to comment.