Skip to content

Commit a7a838a

Browse files
committed
Fixed tests and race condition potential
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent b0f3cd9 commit a7a838a

File tree

4 files changed

+34
-84
lines changed

4 files changed

+34
-84
lines changed

java/src/org/openqa/selenium/grid/node/local/LocalNode.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -944,18 +944,20 @@ public void drain() {
944944
}
945945

946946
private void checkSessionCount() {
947-
if (this.drainAfterSessions.get()) {
948-
int remainingSessions = this.sessionCount.decrementAndGet();
949-
LOG.log(
950-
Debug.getDebugLogLevel(),
951-
"{0} remaining sessions before draining Node",
952-
remainingSessions);
953-
if (remainingSessions <= 0) {
954-
LOG.info(
955-
String.format(
956-
"Draining Node, configured sessions value (%s) has been reached.",
957-
this.configuredSessionCount));
958-
drain();
947+
synchronized (sessionCount) {
948+
if (this.drainAfterSessions.get()) {
949+
int remainingSessions = this.sessionCount.decrementAndGet();
950+
LOG.log(
951+
Debug.getDebugLogLevel(),
952+
"{0} remaining sessions before draining Node",
953+
remainingSessions);
954+
if (remainingSessions <= 0) {
955+
LOG.info(
956+
String.format(
957+
"Draining Node, configured sessions value (%s) has been reached.",
958+
this.configuredSessionCount));
959+
drain();
960+
}
959961
}
960962
}
961963
}

java/test/org/openqa/selenium/grid/e2e/BUILD.bazel

Lines changed: 0 additions & 20 deletions
This file was deleted.

java/test/org/openqa/selenium/grid/e2e/SessionTimeoutTest.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

java/test/org/openqa/selenium/grid/router/StressTest.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import static java.nio.charset.StandardCharsets.UTF_8;
2121
import static java.util.concurrent.TimeUnit.MINUTES;
2222
import static org.assertj.core.api.Assertions.assertThat;
23+
import static org.junit.jupiter.api.Assertions.assertThrows;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
2325

2426
import java.io.StringReader;
2527
import java.util.LinkedList;
@@ -33,6 +35,7 @@
3335
import org.junit.jupiter.api.BeforeEach;
3436
import org.junit.jupiter.api.Test;
3537
import org.openqa.selenium.By;
38+
import org.openqa.selenium.NoSuchSessionException;
3639
import org.openqa.selenium.WebDriver;
3740
import org.openqa.selenium.grid.config.MapConfig;
3841
import org.openqa.selenium.grid.config.MemoizedConfig;
@@ -65,7 +68,12 @@ public void setupServers() {
6568
DeploymentTypes.DISTRIBUTED.start(
6669
browser.getCapabilities(),
6770
new TomlConfig(
68-
new StringReader("[node]\n" + "driver-implementation = " + browser.displayName())));
71+
new StringReader(
72+
"[node]\n"
73+
+ "driver-implementation = "
74+
+ browser.displayName()
75+
+ "\n"
76+
+ "session-timeout = 15")));
6977
tearDowns.add(deployment);
7078

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

125133
CompletableFuture.allOf(futures).get(4, MINUTES);
126134
}
135+
136+
@Test
137+
void testStopTimedOutSession() throws Exception {
138+
assertThat(server.isStarted()).isTrue();
139+
WebDriver driver =
140+
RemoteWebDriver.builder().oneOf(browser.getCapabilities()).address(server.getUrl()).build();
141+
driver.get(appServer.getUrl().toString());
142+
Thread.sleep(15000);
143+
NoSuchSessionException exception = assertThrows(NoSuchSessionException.class, driver::getTitle);
144+
assertTrue(exception.getMessage().startsWith("Cannot find session with id:"));
145+
}
127146
}

0 commit comments

Comments
 (0)