diff --git a/java/src/org/openqa/selenium/grid/node/local/LocalNode.java b/java/src/org/openqa/selenium/grid/node/local/LocalNode.java index 7304db8a878476..4a3d7dd0815a1f 100644 --- a/java/src/org/openqa/selenium/grid/node/local/LocalNode.java +++ b/java/src/org/openqa/selenium/grid/node/local/LocalNode.java @@ -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(); + } } } } diff --git a/java/test/org/openqa/selenium/grid/e2e/BUILD.bazel b/java/test/org/openqa/selenium/grid/e2e/BUILD.bazel deleted file mode 100644 index da013678c69c1a..00000000000000 --- a/java/test/org/openqa/selenium/grid/e2e/BUILD.bazel +++ /dev/null @@ -1,20 +0,0 @@ -load("@rules_jvm_external//:defs.bzl", "artifact") -load("//java:defs.bzl", "JUNIT5_DEPS", "java_selenium_test_suite") - -java_selenium_test_suite( - name = "large-tests", - size = "large", - srcs = glob(["*.java"]), - browsers = [ - "chrome", - ], - deps = [ - "//java/src/org/openqa/selenium:core", - "//java/src/org/openqa/selenium/chrome", - "//java/src/org/openqa/selenium/grid", - "//java/src/org/openqa/selenium/remote/http", - artifact("com.google.guava:guava"), - artifact("org.junit.jupiter:junit-jupiter-api"), - artifact("org.assertj:assertj-core"), - ] + JUNIT5_DEPS, -) diff --git a/java/test/org/openqa/selenium/grid/e2e/SessionTimeoutTest.java b/java/test/org/openqa/selenium/grid/e2e/SessionTimeoutTest.java deleted file mode 100644 index cf9df66fdd91ed..00000000000000 --- a/java/test/org/openqa/selenium/grid/e2e/SessionTimeoutTest.java +++ /dev/null @@ -1,51 +0,0 @@ -// Licensed to the Software Freedom Conservancy (SFC) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The SFC licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package org.openqa.selenium.grid.e2e; - -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.net.URI; -import org.assertj.core.api.Assumptions; -import org.junit.jupiter.api.Test; -import org.openqa.selenium.NoSuchSessionException; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeOptions; -import org.openqa.selenium.grid.Bootstrap; -import org.openqa.selenium.remote.RemoteWebDriver; - -public class SessionTimeoutTest { - @Test - void testSessionTimeout() throws Exception { - Assumptions.assumeThat(System.getProperty("webdriver.chrome.binary")).isNull(); - Bootstrap.main(("hub --host 127.0.0.1 --port 4444").split(" ")); - Bootstrap.main( - ("node --host 127.0.0.1 --port 5555 --session-timeout 12 --selenium-manager true") - .split(" ")); - - var options = new ChromeOptions(); - options.addArguments("--disable-search-engine-choice-screen"); - options.addArguments("--headless=new"); - - WebDriver driver = new RemoteWebDriver(URI.create("http://localhost:4444").toURL(), options); - driver.get("http://localhost:4444"); - Thread.sleep(12000); - NoSuchSessionException exception = assertThrows(NoSuchSessionException.class, driver::getTitle); - assertTrue(exception.getMessage().startsWith("Cannot find session with id:")); - } -} diff --git a/java/test/org/openqa/selenium/grid/router/StressTest.java b/java/test/org/openqa/selenium/grid/router/StressTest.java index a2c432229297fd..d9fb088504e979 100644 --- a/java/test/org/openqa/selenium/grid/router/StressTest.java +++ b/java/test/org/openqa/selenium/grid/router/StressTest.java @@ -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; @@ -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; @@ -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(); @@ -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:")); + } }