Skip to content

Commit 2263fb7

Browse files
authored
[grid] Remove new session event listener from Distributor. Shutdown executors in Distributor
1 parent de48e08 commit 2263fb7

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

java/server/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java

+12-9
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.openqa.selenium.grid.data.CreateSessionRequest;
3232
import org.openqa.selenium.grid.data.CreateSessionResponse;
3333
import org.openqa.selenium.grid.data.DistributorStatus;
34-
import org.openqa.selenium.grid.data.NewSessionRequestEvent;
3534
import org.openqa.selenium.grid.data.NodeAddedEvent;
3635
import org.openqa.selenium.grid.data.NodeDrainComplete;
3736
import org.openqa.selenium.grid.data.NodeHeartBeatEvent;
@@ -72,6 +71,7 @@
7271
import org.openqa.selenium.remote.tracing.Tracer;
7372
import org.openqa.selenium.status.HasReadyState;
7473

74+
import java.io.Closeable;
7575
import java.io.UncheckedIOException;
7676
import java.time.Duration;
7777
import java.util.ArrayList;
@@ -101,7 +101,7 @@
101101
import static org.openqa.selenium.remote.tracing.AttributeKey.SESSION_URI;
102102
import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;
103103

104-
public class LocalDistributor extends Distributor {
104+
public class LocalDistributor extends Distributor implements Closeable {
105105

106106
private static final Logger LOG = Logger.getLogger(LocalDistributor.class.getName());
107107

@@ -112,6 +112,7 @@ public class LocalDistributor extends Distributor {
112112
private final SlotSelector slotSelector;
113113
private final Secret registrationSecret;
114114
private final Regularly hostChecker = new Regularly("distributor host checker");
115+
private final Regularly purgeDeadNodes = new Regularly("Purge deadNodes");
115116
private final Map<NodeId, Runnable> allChecks = new HashMap<>();
116117
private final Duration healthcheckInterval;
117118

@@ -120,7 +121,7 @@ public class LocalDistributor extends Distributor {
120121
private final Map<NodeId, Node> nodes;
121122

122123
private final NewSessionQueue sessionQueue;
123-
private final Regularly regularly;
124+
private final Regularly createNewSession;
124125

125126
private final boolean rejectUnsupportedCaps;
126127

@@ -158,7 +159,7 @@ public LocalDistributor(
158159
}
159160
}));
160161

161-
regularly = new Regularly(
162+
createNewSession = new Regularly(
162163
Executors.newSingleThreadScheduledExecutor(
163164
r -> {
164165
Thread thread = new Thread(r);
@@ -169,10 +170,9 @@ public LocalDistributor(
169170

170171
NewSessionRunnable newSessionRunnable = new NewSessionRunnable();
171172
bus.addListener(NodeDrainComplete.listener(this::remove));
172-
bus.addListener(NewSessionRequestEvent.listener(ignored -> newSessionRunnable.run()));
173173

174-
regularly.submit(model::purgeDeadNodes, Duration.ofSeconds(30), Duration.ofSeconds(30));
175-
regularly.submit(newSessionRunnable, Duration.ofSeconds(5), Duration.ofSeconds(5));
174+
purgeDeadNodes.submit(model::purgeDeadNodes, Duration.ofSeconds(30), Duration.ofSeconds(30));
175+
createNewSession.submit(newSessionRunnable, Duration.ofSeconds(5), Duration.ofSeconds(5));
176176
}
177177

178178
public static Distributor create(Config config) {
@@ -541,9 +541,12 @@ private boolean reserve(SlotId id) {
541541
}
542542
}
543543

544-
public void callExecutorShutdown() {
544+
@Override
545+
public void close() {
545546
LOG.info("Shutting down Distributor executor service");
546-
regularly.shutdown();
547+
purgeDeadNodes.shutdown();
548+
hostChecker.shutdown();
549+
createNewSession.shutdown();
547550
}
548551

549552
public class NewSessionRunnable implements Runnable {

java/server/test/org/openqa/selenium/grid/router/NewSessionCreationTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void ensureJsCannotCreateANewSession() throws URISyntaxException {
9898
events,
9999
new DefaultSlotMatcher(),
100100
Duration.ofSeconds(2),
101-
Duration.ofSeconds(2),
101+
Duration.ofSeconds(60),
102102
registrationSecret);
103103

104104
Distributor distributor = new LocalDistributor(
@@ -236,7 +236,7 @@ public void shouldNotRetryNewSessionRequestOnUnexpectedError() throws URISyntaxE
236236
assertThat(httpResponse.getStatus()).isEqualTo(HTTP_INTERNAL_ERROR);
237237
}
238238

239-
@Test(timeout = 5000L)
239+
@Test(timeout = 10000L)
240240
public void shouldRejectRequestForUnsupportedCaps() throws URISyntaxException {
241241
Capabilities capabilities = new ImmutableCapabilities("browserName", "cheese");
242242
URI nodeUri = new URI("http://localhost:4444");

0 commit comments

Comments
 (0)