Skip to content

Commit a1f47e8

Browse files
RenderMichaelpujaganishs96c
authored
Add explicit reference to cdp types (#15194)
* [java] Ensure purging dead nodes service interval is configurable (#15175) Fixes #15168 * [bazel] Bump JS rulesets (#15187) * Add explicit reference to cdp types --------- Co-authored-by: Puja Jagani <[email protected]> Co-authored-by: Simon Stewart <[email protected]>
1 parent c3a70ce commit a1f47e8

21 files changed

+157
-58
lines changed

MODULE.bazel

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
module(name = "selenium")
22

33
bazel_dep(name = "apple_rules_lint", version = "0.4.0")
4-
bazel_dep(name = "aspect_bazel_lib", version = "2.10.0")
4+
bazel_dep(name = "aspect_bazel_lib", version = "2.13.0")
55
bazel_dep(name = "aspect_rules_esbuild", version = "0.21.0")
6-
bazel_dep(name = "aspect_rules_js", version = "2.0.1")
7-
bazel_dep(name = "aspect_rules_ts", version = "3.1.0")
6+
bazel_dep(name = "aspect_rules_js", version = "2.1.3")
7+
bazel_dep(name = "aspect_rules_ts", version = "3.4.0")
88
bazel_dep(name = "bazel_features", version = "1.23.0")
99
bazel_dep(name = "bazel_skylib", version = "1.7.1")
1010
bazel_dep(name = "buildifier_prebuilt", version = "6.4.0")
1111
bazel_dep(name = "contrib_rules_jvm", version = "0.27.0")
12-
bazel_dep(name = "platforms", version = "0.0.10")
12+
bazel_dep(name = "platforms", version = "0.0.11")
1313

1414
# Required for the closure rules
1515
bazel_dep(name = "protobuf", version = "29.2", dev_dependency = True, repo_name = "com_google_protobuf")

java/src/org/openqa/selenium/grid/commands/Hub.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ protected Handlers createHandlers(Config config) {
162162
distributorOptions.shouldRejectUnsupportedCaps(),
163163
newSessionRequestOptions.getSessionRequestRetryInterval(),
164164
distributorOptions.getNewSessionThreadPoolSize(),
165-
distributorOptions.getSlotMatcher());
165+
distributorOptions.getSlotMatcher(),
166+
distributorOptions.getPurgeNodesInterval());
166167
handler.addHandler(distributor);
167168

168169
Router router = new Router(tracer, clientFactory, sessions, queue, distributor);

java/src/org/openqa/selenium/grid/commands/Standalone.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ protected Handlers createHandlers(Config config) {
168168
distributorOptions.shouldRejectUnsupportedCaps(),
169169
newSessionRequestOptions.getSessionRequestRetryInterval(),
170170
distributorOptions.getNewSessionThreadPoolSize(),
171-
distributorOptions.getSlotMatcher());
171+
distributorOptions.getSlotMatcher(),
172+
distributorOptions.getPurgeNodesInterval());
172173
combinedHandler.addHandler(distributor);
173174

174175
Router router = new Router(tracer, clientFactory, sessions, queue, distributor);

java/src/org/openqa/selenium/grid/distributor/config/DistributorFlags.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_DISTRIBUTOR_IMPLEMENTATION;
2222
import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_HEALTHCHECK_INTERVAL;
2323
import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_NEWSESSION_THREADPOOL_SIZE;
24+
import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_PURGE_NODES_INTERVAL;
2425
import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_REJECT_UNSUPPORTED_CAPS;
2526
import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_SLOT_MATCHER;
2627
import static org.openqa.selenium.grid.distributor.config.DistributorOptions.DEFAULT_SLOT_SELECTOR_IMPLEMENTATION;
@@ -115,6 +116,14 @@ public class DistributorFlags implements HasRoles {
115116
@ConfigValue(section = DISTRIBUTOR_SECTION, name = "newsession-threadpool-size", example = "4")
116117
public int newSessionThreadPoolSize = DEFAULT_NEWSESSION_THREADPOOL_SIZE;
117118

119+
@Parameter(
120+
names = {"--purge-nodes-interval"},
121+
description =
122+
"How often, in seconds, will the Distributor purge Nodes that have been down for a while."
123+
+ " This is calculated based on the heartbeat received from a particular node. ")
124+
@ConfigValue(section = DISTRIBUTOR_SECTION, name = "purge-nodes-interval", example = "30")
125+
public int purgeNodesInterval = DEFAULT_PURGE_NODES_INTERVAL;
126+
118127
@Override
119128
public Set<Role> getRoles() {
120129
return Collections.singleton(DISTRIBUTOR_ROLE);

java/src/org/openqa/selenium/grid/distributor/config/DistributorOptions.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
public class DistributorOptions {
3232

3333
public static final int DEFAULT_HEALTHCHECK_INTERVAL = 120;
34+
public static final int DEFAULT_PURGE_NODES_INTERVAL = 30;
3435
public static final String DISTRIBUTOR_SECTION = "distributor";
3536
static final String DEFAULT_DISTRIBUTOR_IMPLEMENTATION =
3637
"org.openqa.selenium.grid.distributor.local.LocalDistributor";
@@ -97,6 +98,17 @@ public Duration getHealthCheckInterval() {
9798
return Duration.ofSeconds(seconds);
9899
}
99100

101+
public Duration getPurgeNodesInterval() {
102+
// If the user sets 0s or less, we default to 0s and disable the purge dead nodes service.
103+
int seconds =
104+
Math.max(
105+
config
106+
.getInt(DISTRIBUTOR_SECTION, "purge-nodes-interval")
107+
.orElse(DEFAULT_PURGE_NODES_INTERVAL),
108+
0);
109+
return Duration.ofSeconds(seconds);
110+
}
111+
100112
public Distributor getDistributor() {
101113
return config.getClass(
102114
DISTRIBUTOR_SECTION,

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public class LocalDistributor extends Distributor implements Closeable {
142142
private final GridModel model;
143143
private final Map<NodeId, Node> nodes;
144144
private final SlotMatcher slotMatcher;
145+
private final Duration purgeNodesInterval;
145146

146147
private final ScheduledExecutorService newSessionService =
147148
Executors.newSingleThreadScheduledExecutor(
@@ -188,7 +189,8 @@ public LocalDistributor(
188189
boolean rejectUnsupportedCaps,
189190
Duration sessionRequestRetryInterval,
190191
int newSessionThreadPoolSize,
191-
SlotMatcher slotMatcher) {
192+
SlotMatcher slotMatcher,
193+
Duration purgeNodesInterval) {
192194
super(tracer, clientFactory, registrationSecret);
193195
this.tracer = Require.nonNull("Tracer", tracer);
194196
this.bus = Require.nonNull("Event bus", bus);
@@ -202,6 +204,7 @@ public LocalDistributor(
202204
this.nodes = new ConcurrentHashMap<>();
203205
this.rejectUnsupportedCaps = rejectUnsupportedCaps;
204206
this.slotMatcher = slotMatcher;
207+
this.purgeNodesInterval = purgeNodesInterval;
205208
Require.nonNull("Session request interval", sessionRequestRetryInterval);
206209

207210
bus.addListener(NodeStatusEvent.listener(this::register));
@@ -232,8 +235,14 @@ public LocalDistributor(
232235
NewSessionRunnable newSessionRunnable = new NewSessionRunnable();
233236
bus.addListener(NodeDrainComplete.listener(this::remove));
234237

235-
purgeDeadNodesService.scheduleAtFixedRate(
236-
GuardedRunnable.guard(model::purgeDeadNodes), 30, 30, TimeUnit.SECONDS);
238+
// Disable purge dead nodes service if interval is set to zero
239+
if (!this.purgeNodesInterval.isZero()) {
240+
purgeDeadNodesService.scheduleAtFixedRate(
241+
GuardedRunnable.guard(model::purgeDeadNodes),
242+
this.purgeNodesInterval.getSeconds(),
243+
this.purgeNodesInterval.getSeconds(),
244+
TimeUnit.SECONDS);
245+
}
237246

238247
nodeHealthCheckService.scheduleAtFixedRate(
239248
runNodeHealthChecks(),
@@ -276,7 +285,8 @@ public static Distributor create(Config config) {
276285
distributorOptions.shouldRejectUnsupportedCaps(),
277286
newSessionQueueOptions.getSessionRequestRetryInterval(),
278287
distributorOptions.getNewSessionThreadPoolSize(),
279-
distributorOptions.getSlotMatcher());
288+
distributorOptions.getSlotMatcher(),
289+
distributorOptions.getPurgeNodesInterval());
280290
}
281291

282292
@Override

java/test/org/openqa/selenium/grid/distributor/AddingNodesTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ void shouldBeAbleToRegisterALocalNode() throws URISyntaxException {
143143
false,
144144
Duration.ofSeconds(5),
145145
newSessionThreadPoolSize,
146-
new DefaultSlotMatcher());
146+
new DefaultSlotMatcher(),
147+
Duration.ofSeconds(30));
147148

148149
distributor =
149150
new RemoteDistributor(
@@ -183,7 +184,8 @@ void shouldBeAbleToRegisterACustomNode() throws URISyntaxException {
183184
false,
184185
Duration.ofSeconds(5),
185186
newSessionThreadPoolSize,
186-
new DefaultSlotMatcher())) {
187+
new DefaultSlotMatcher(),
188+
Duration.ofSeconds(30))) {
187189

188190
distributor =
189191
new RemoteDistributor(
@@ -223,7 +225,8 @@ void shouldBeAbleToRegisterNodesByListeningForEvents() throws URISyntaxException
223225
false,
224226
Duration.ofSeconds(5),
225227
newSessionThreadPoolSize,
226-
new DefaultSlotMatcher())) {
228+
new DefaultSlotMatcher(),
229+
Duration.ofSeconds(30))) {
227230

228231
distributor =
229232
new RemoteDistributor(
@@ -272,7 +275,8 @@ void shouldKeepOnlyOneNodeWhenTwoRegistrationsHaveTheSameUriByListeningForEvents
272275
false,
273276
Duration.ofSeconds(5),
274277
newSessionThreadPoolSize,
275-
new DefaultSlotMatcher())) {
278+
new DefaultSlotMatcher(),
279+
Duration.ofSeconds(30))) {
276280

277281
distributor =
278282
new RemoteDistributor(
@@ -314,7 +318,8 @@ void distributorShouldUpdateStateOfExistingNodeWhenNodePublishesStateChange()
314318
false,
315319
Duration.ofSeconds(5),
316320
newSessionThreadPoolSize,
317-
new DefaultSlotMatcher())) {
321+
new DefaultSlotMatcher(),
322+
Duration.ofSeconds(30))) {
318323

319324
distributor =
320325
new RemoteDistributor(

java/test/org/openqa/selenium/grid/distributor/DistributorDrainingTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ void drainedNodeDoesNotShutDownIfNotEmpty() throws InterruptedException {
8181
false,
8282
Duration.ofSeconds(5),
8383
newSessionThreadPoolSize,
84-
new DefaultSlotMatcher());
84+
new DefaultSlotMatcher(),
85+
Duration.ofSeconds(30));
8586
local.add(node);
8687
waitToHaveCapacity(local);
8788

@@ -139,7 +140,8 @@ void drainedNodeShutsDownAfterSessionsFinish() throws InterruptedException {
139140
false,
140141
Duration.ofSeconds(5),
141142
newSessionThreadPoolSize,
142-
new DefaultSlotMatcher());
143+
new DefaultSlotMatcher(),
144+
Duration.ofSeconds(30));
143145
local.add(node);
144146
waitToHaveCapacity(local);
145147

@@ -211,7 +213,8 @@ void testDrainedNodeShutsDownOnceEmpty() throws InterruptedException {
211213
false,
212214
Duration.ofSeconds(5),
213215
newSessionThreadPoolSize,
214-
new DefaultSlotMatcher());
216+
new DefaultSlotMatcher(),
217+
Duration.ofSeconds(30));
215218
local.add(node);
216219
waitToHaveCapacity(local);
217220

@@ -261,7 +264,8 @@ void drainingNodeDoesNotAcceptNewSessions() {
261264
false,
262265
Duration.ofSeconds(5),
263266
newSessionThreadPoolSize,
264-
new DefaultSlotMatcher());
267+
new DefaultSlotMatcher(),
268+
Duration.ofSeconds(30));
265269
local.add(node);
266270
local.drain(node.getId());
267271

java/test/org/openqa/selenium/grid/distributor/DistributorNodeAvailabilityTest.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ void registeringTheSameNodeMultipleTimesOnlyCountsTheFirstTime() {
7878
false,
7979
Duration.ofSeconds(5),
8080
newSessionThreadPoolSize,
81-
new DefaultSlotMatcher());
81+
new DefaultSlotMatcher(),
82+
Duration.ofSeconds(30));
8283

8384
local.add(node);
8485
local.add(node);
@@ -122,7 +123,8 @@ void shouldBeAbleToRemoveANode() throws MalformedURLException {
122123
false,
123124
Duration.ofSeconds(5),
124125
newSessionThreadPoolSize,
125-
new DefaultSlotMatcher());
126+
new DefaultSlotMatcher(),
127+
Duration.ofSeconds(30));
126128
Distributor distributor =
127129
new RemoteDistributor(
128130
tracer,
@@ -178,7 +180,8 @@ void shouldIncludeHostsThatAreUpInHostList() {
178180
false,
179181
Duration.ofSeconds(5),
180182
newSessionThreadPoolSize,
181-
new DefaultSlotMatcher());
183+
new DefaultSlotMatcher(),
184+
Duration.ofSeconds(30));
182185
handler.addHandler(local);
183186
local.add(alwaysDown);
184187
waitForAllNodesToMeetCondition(local, 1, DOWN);
@@ -258,7 +261,8 @@ void shouldNotRemoveNodeWhoseHealthCheckPassesBeforeThreshold() throws Interrupt
258261
false,
259262
Duration.ofSeconds(5),
260263
newSessionThreadPoolSize,
261-
new DefaultSlotMatcher());
264+
new DefaultSlotMatcher(),
265+
Duration.ofSeconds(30));
262266
handler.addHandler(local);
263267
local.add(node);
264268

@@ -313,7 +317,8 @@ void shouldReturnNodesThatWereDownToPoolOfNodesOnceTheyMarkTheirHealthCheckPasse
313317
false,
314318
Duration.ofSeconds(5),
315319
newSessionThreadPoolSize,
316-
new DefaultSlotMatcher());
320+
new DefaultSlotMatcher(),
321+
Duration.ofSeconds(30));
317322
handler.addHandler(local);
318323
local.add(node);
319324
waitForAllNodesToMeetCondition(local, 1, DOWN);
@@ -366,7 +371,8 @@ void shouldBeAbleToAddANodeAndCreateASession() {
366371
false,
367372
Duration.ofSeconds(5),
368373
newSessionThreadPoolSize,
369-
new DefaultSlotMatcher());
374+
new DefaultSlotMatcher(),
375+
Duration.ofSeconds(30));
370376
local.add(node);
371377
waitToHaveCapacity(local);
372378

java/test/org/openqa/selenium/grid/distributor/DistributorTest.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ void creatingANewSessionWithoutANodeEndsInFailure() {
6969
false,
7070
Duration.ofSeconds(5),
7171
newSessionThreadPoolSize,
72-
new DefaultSlotMatcher());
72+
new DefaultSlotMatcher(),
73+
Duration.ofSeconds(30));
7374
Either<SessionNotCreatedException, CreateSessionResponse> result =
7475
local.newSession(createRequest(caps));
7576
assertThatEither(result).isLeft();
@@ -109,7 +110,8 @@ void creatingASessionAddsItToTheSessionMap() {
109110
false,
110111
Duration.ofSeconds(5),
111112
newSessionThreadPoolSize,
112-
new DefaultSlotMatcher());
113+
new DefaultSlotMatcher(),
114+
Duration.ofSeconds(30));
113115
local.add(node);
114116
waitToHaveCapacity(local);
115117

@@ -160,7 +162,8 @@ void shouldReleaseSlotOnceSessionEnds() {
160162
false,
161163
Duration.ofSeconds(5),
162164
newSessionThreadPoolSize,
163-
new DefaultSlotMatcher());
165+
new DefaultSlotMatcher(),
166+
Duration.ofSeconds(30));
164167
local.add(node);
165168
waitToHaveCapacity(local);
166169

@@ -223,7 +226,8 @@ void shouldNotStartASessionIfTheCapabilitiesAreNotSupported() {
223226
false,
224227
Duration.ofSeconds(5),
225228
newSessionThreadPoolSize,
226-
new DefaultSlotMatcher());
229+
new DefaultSlotMatcher(),
230+
Duration.ofSeconds(30));
227231
handler.addHandler(distributor);
228232

229233
Node node = createNode(caps, 1, 0);
@@ -273,7 +277,8 @@ void attemptingToStartASessionWhichFailsMarksAsTheSlotAsAvailable() {
273277
false,
274278
Duration.ofSeconds(5),
275279
newSessionThreadPoolSize,
276-
new DefaultSlotMatcher());
280+
new DefaultSlotMatcher(),
281+
Duration.ofSeconds(30));
277282
local.add(node);
278283
waitToHaveCapacity(local);
279284

@@ -320,7 +325,8 @@ void shouldFallbackToSecondAvailableCapabilitiesIfFirstNotAvailable() {
320325
false,
321326
Duration.ofSeconds(5),
322327
newSessionThreadPoolSize,
323-
new DefaultSlotMatcher());
328+
new DefaultSlotMatcher(),
329+
Duration.ofSeconds(30));
324330

325331
local.add(firstNode);
326332
local.add(secondNode);
@@ -368,7 +374,8 @@ void shouldFallbackToSecondAvailableCapabilitiesIfFirstThrowsOnCreation() {
368374
false,
369375
Duration.ofSeconds(5),
370376
newSessionThreadPoolSize,
371-
new DefaultSlotMatcher());
377+
new DefaultSlotMatcher(),
378+
Duration.ofSeconds(30));
372379
local.add(brokenNode);
373380
local.add(node);
374381
waitForAllNodesToHaveCapacity(local, 2);

0 commit comments

Comments
 (0)