Improving `shouldBeAbleToAddMultipleSessionsConcurrently` by adding an active wait.
package org.openqa.selenium.grid.distributor.local;
+import static java.util.Collections.newSetFromMap;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+import static org.openqa.selenium.grid.data.Availability.DRAINING;
+import static org.openqa.selenium.grid.data.Availability.UP;
+import static org.openqa.selenium.remote.Dialect.W3C;
+import static org.openqa.selenium.remote.http.HttpMethod.GET;
+
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.grid.data.DefaultSlotMatcher;
import org.openqa.selenium.grid.data.DistributorStatus;
import org.openqa.selenium.grid.data.NodeStatus;
-import org.openqa.selenium.grid.data.NodeStatusEvent;
import org.openqa.selenium.grid.data.RequestId;
import org.openqa.selenium.grid.data.Session;
import org.openqa.selenium.grid.data.SessionRequest;
import org.openqa.selenium.internal.Either;
import org.openqa.selenium.remote.HttpSessionId;
import org.openqa.selenium.remote.SessionId;
-import org.openqa.selenium.remote.http.ClientConfig;
-import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.http.HttpHandler;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;
import org.openqa.selenium.remote.tracing.DefaultTestTracer;
import org.openqa.selenium.remote.tracing.Tracer;
+import org.openqa.selenium.support.ui.FluentWait;
+import org.openqa.selenium.support.ui.Wait;
import java.io.UncheckedIOException;
import java.net.URI;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
-import static java.util.Collections.newSetFromMap;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
-import static org.openqa.selenium.grid.data.Availability.DRAINING;
-import static org.openqa.selenium.grid.data.Availability.UP;
-import static org.openqa.selenium.remote.Dialect.W3C;
-import static org.openqa.selenium.remote.http.HttpMethod.GET;
-
public class LocalDistributorTest {
private final Secret registrationSecret = new Secret("bavarian smoked");
private EventBus bus;
private URI uri;
private Node localNode;
+ private Wait<Object> wait;
@Before
public void setUp() throws URISyntaxException {
@@ -100,6 +100,9 @@ public void setUp() throws URISyntaxException {
.add(caps, new TestSessionFactory((id, c) -> new Handler(c)))
.maximumConcurrentSessions(2)
.build();
+
+ wait = new FluentWait<>(
+ new Object()).ignoring(Throwable.class).withTimeout(Duration.ofSeconds(5));
}
@Test
@@ -244,6 +247,7 @@ public HttpResponse execute(HttpRequest req) {
false);
distributor.add(node);
+ wait.until(obj -> distributor.getStatus().hasCapacity());
SessionRequest sessionRequest =
new SessionRequest(
