Skip to content

Commit

Permalink
[grid] Using new session request retry interval
Browse files Browse the repository at this point in the history
This config value was being read properly but it
was not being used where it matters, which is
when the Distributor requests the new session
requests from the Queue.

Fixes SeleniumHQ/docker-selenium#1394
  • Loading branch information
diemol committed Sep 14, 2021
1 parent 6bab9ef commit 47e47d9
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 137 deletions.
3 changes: 2 additions & 1 deletion java/src/org/openqa/selenium/grid/commands/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ protected Handlers createHandlers(Config config) {
distributorOptions.getSlotSelector(),
secret,
distributorOptions.getHealthCheckInterval(),
distributorOptions.shouldRejectUnsupportedCaps());
distributorOptions.shouldRejectUnsupportedCaps(),
newSessionRequestOptions.getSessionRequestRetryInterval());
handler.addHandler(distributor);

Router router = new Router(tracer, clientFactory, sessions, queue, distributor);
Expand Down
3 changes: 2 additions & 1 deletion java/src/org/openqa/selenium/grid/commands/Standalone.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ protected Handlers createHandlers(Config config) {
distributorOptions.getSlotSelector(),
registrationSecret,
distributorOptions.getHealthCheckInterval(),
distributorOptions.shouldRejectUnsupportedCaps());
distributorOptions.shouldRejectUnsupportedCaps(),
newSessionRequestOptions.getSessionRequestRetryInterval());
combinedHandler.addHandler(distributor);

Routable router = new Router(tracer, clientFactory, sessions, queue, distributor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@

package org.openqa.selenium.grid.distributor.local;

import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static org.openqa.selenium.grid.data.Availability.DOWN;
import static org.openqa.selenium.grid.data.Availability.DRAINING;
import static org.openqa.selenium.internal.Debug.getDebugLogLevel;
import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES;
import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES_EVENT;
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID;
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID_EVENT;
import static org.openqa.selenium.remote.tracing.AttributeKey.SESSION_URI;
import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;

import com.google.common.collect.ImmutableSet;

import org.openqa.selenium.Beta;
Expand Down Expand Up @@ -92,17 +103,6 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;

import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static org.openqa.selenium.grid.data.Availability.DOWN;
import static org.openqa.selenium.grid.data.Availability.DRAINING;
import static org.openqa.selenium.internal.Debug.getDebugLogLevel;
import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES;
import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES_EVENT;
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID;
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID_EVENT;
import static org.openqa.selenium.remote.tracing.AttributeKey.SESSION_URI;
import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;

public class LocalDistributor extends Distributor implements Closeable {

private static final Logger LOG = Logger.getLogger(LocalDistributor.class.getName());
Expand All @@ -117,6 +117,7 @@ public class LocalDistributor extends Distributor implements Closeable {
private final Regularly purgeDeadNodes = new Regularly("Purge deadNodes");
private final Map<NodeId, Runnable> allChecks = new HashMap<>();
private final Duration healthcheckInterval;
private final Duration sessionRequestRetryInterval;

private final ReadWriteLock lock = new ReentrantReadWriteLock(/* fair */ true);
private final GridModel model;
Expand Down Expand Up @@ -145,7 +146,8 @@ public LocalDistributor(
SlotSelector slotSelector,
Secret registrationSecret,
Duration healthcheckInterval,
boolean rejectUnsupportedCaps) {
boolean rejectUnsupportedCaps,
Duration sessionRequestRetryInterval) {
super(tracer, clientFactory, registrationSecret);
this.tracer = Require.nonNull("Tracer", tracer);
this.bus = Require.nonNull("Event bus", bus);
Expand All @@ -155,6 +157,8 @@ public LocalDistributor(
this.slotSelector = Require.nonNull("Slot selector", slotSelector);
this.registrationSecret = Require.nonNull("Registration secret", registrationSecret);
this.healthcheckInterval = Require.nonNull("Health check interval", healthcheckInterval);
this.sessionRequestRetryInterval = Require.nonNull("Session request interval",
sessionRequestRetryInterval);
this.model = new GridModel(bus);
this.nodes = new ConcurrentHashMap<>();
this.rejectUnsupportedCaps = rejectUnsupportedCaps;
Expand Down Expand Up @@ -183,7 +187,8 @@ public LocalDistributor(
bus.addListener(NodeDrainComplete.listener(this::remove));

purgeDeadNodes.submit(model::purgeDeadNodes, Duration.ofSeconds(30), Duration.ofSeconds(30));
createNewSession.submit(newSessionRunnable, Duration.ofSeconds(5), Duration.ofSeconds(5));
createNewSession
.submit(newSessionRunnable, sessionRequestRetryInterval, sessionRequestRetryInterval);
}

public static Distributor create(Config config) {
Expand All @@ -193,7 +198,8 @@ public static Distributor create(Config config) {
HttpClient.Factory clientFactory = new NetworkOptions(config).getHttpClientFactory(tracer);
SessionMap sessions = new SessionMapOptions(config).getSessionMap();
SecretOptions secretOptions = new SecretOptions(config);
NewSessionQueue sessionQueue = new NewSessionQueueOptions(config).getSessionQueue(
NewSessionQueueOptions newSessionQueueOptions = new NewSessionQueueOptions(config);
NewSessionQueue sessionQueue = newSessionQueueOptions.getSessionQueue(
"org.openqa.selenium.grid.sessionqueue.remote.RemoteNewSessionQueue");
return new LocalDistributor(
tracer,
Expand All @@ -204,7 +210,8 @@ public static Distributor create(Config config) {
distributorOptions.getSlotSelector(),
secretOptions.getRegistrationSecret(),
distributorOptions.getHealthCheckInterval(),
distributorOptions.shouldRejectUnsupportedCaps());
distributorOptions.shouldRejectUnsupportedCaps(),
newSessionQueueOptions.getSessionRequestRetryInterval());
}

@Override
Expand Down
28 changes: 16 additions & 12 deletions java/test/org/openqa/selenium/grid/distributor/AddingNodesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@

package org.openqa.selenium.grid.distributor;

import static com.google.common.collect.Iterables.getOnlyElement;
import static org.junit.Assert.assertEquals;
import static org.openqa.selenium.grid.data.Availability.UP;
import static org.openqa.selenium.remote.Dialect.W3C;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;

import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Capabilities;
Expand Down Expand Up @@ -52,10 +58,8 @@
import org.openqa.selenium.grid.testing.PassthroughHttpClient;
import org.openqa.selenium.grid.testing.TestSessionFactory;
import org.openqa.selenium.grid.web.CombinedHandler;
import org.openqa.selenium.grid.web.RoutableHttpClientFactory;
import org.openqa.selenium.internal.Either;
import org.openqa.selenium.remote.SessionId;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;
import org.openqa.selenium.remote.tracing.DefaultTestTracer;
Expand All @@ -76,11 +80,6 @@
import java.util.UUID;
import java.util.function.Function;

import static com.google.common.collect.Iterables.getOnlyElement;
import static org.junit.Assert.assertEquals;
import static org.openqa.selenium.grid.data.Availability.UP;
import static org.openqa.selenium.remote.Dialect.W3C;

public class AddingNodesTest {

private static final Capabilities CAPS = new ImmutableCapabilities("cheese", "gouda");
Expand Down Expand Up @@ -139,7 +138,8 @@ public void shouldBeAbleToRegisterALocalNode() throws URISyntaxException {
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5),
false);
false,
Duration.ofSeconds(5));

distributor = new RemoteDistributor(tracer, new PassthroughHttpClient.Factory(local), externalUrl, registrationSecret);

Expand Down Expand Up @@ -170,7 +170,8 @@ public void shouldBeAbleToRegisterACustomNode() throws URISyntaxException {
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5),
false);
false,
Duration.ofSeconds(5));

distributor = new RemoteDistributor(tracer, new PassthroughHttpClient.Factory(local), externalUrl, registrationSecret);

Expand Down Expand Up @@ -202,7 +203,8 @@ public void shouldBeAbleToRegisterNodesByListeningForEvents() throws URISyntaxEx
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5),
false);
false,
Duration.ofSeconds(5));

distributor = new RemoteDistributor(tracer, new PassthroughHttpClient.Factory(local), externalUrl, registrationSecret);

Expand Down Expand Up @@ -244,7 +246,8 @@ public void shouldKeepOnlyOneNodeWhenTwoRegistrationsHaveTheSameUriByListeningFo
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5),
false);
false,
Duration.ofSeconds(5));

distributor = new RemoteDistributor(tracer, new PassthroughHttpClient.Factory(local), externalUrl, registrationSecret);

Expand Down Expand Up @@ -279,7 +282,8 @@ public void distributorShouldUpdateStateOfExistingNodeWhenNodePublishesStateChan
new DefaultSlotSelector(),
registrationSecret,
Duration.ofMinutes(5),
false);
false,
Duration.ofSeconds(5));

distributor = new RemoteDistributor(tracer, new PassthroughHttpClient.Factory(local), externalUrl, registrationSecret);

Expand Down
Loading

0 comments on commit 47e47d9

Please sign in to comment.