Skip to content

Commit

Permalink
[grid] Small refactor at EndToEndTest [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Nov 13, 2020
1 parent fcf46b5 commit 32d0ef7
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions java/server/test/org/openqa/selenium/grid/router/EndToEndTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
import java.util.UUID;
import java.util.function.Supplier;

import static java.time.Duration.ofSeconds;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -148,7 +147,7 @@ private static TestData createStandalone() {

Server<?> server = new Standalone().asServer(config).start();

waitUntilReady(server);
waitUntilReady(server, Duration.ofSeconds(5));

return new TestData(server, server::stop);
}
Expand Down Expand Up @@ -192,9 +191,9 @@ private static TestData createHubAndNode() {
Server<?> hub = new Hub().asServer(setRandomPort(hubConfig)).start();

Server<?> node = new NodeServer().asServer(setRandomPort(baseConfig)).start();
waitUntilReady(node);
waitUntilReady(node, Duration.ofSeconds(5));

waitUntilReady(hub);
waitUntilReady(hub, Duration.ofSeconds(5));

return new TestData(hub, hub::stop, node::stop);
}
Expand Down Expand Up @@ -242,10 +241,10 @@ private static TestData createFullyDistributed() {
"bind = true"}))),
setRandomPort(sharedConfig)))
.start();
waitUntilReady(eventServer);
waitUntilReady(eventServer, Duration.ofSeconds(5));

Server<?> newSessionQueueServer = new NewSessionQueuerServer().asServer(setRandomPort(sharedConfig)).start();
waitUntilReady(newSessionQueueServer);
waitUntilReady(newSessionQueueServer, Duration.ofSeconds(5));
Config newSessionQueueServerConfig = new TomlConfig(new StringReader(String.join(
"\n",
new String[] {
Expand Down Expand Up @@ -295,9 +294,9 @@ private static TestData createFullyDistributed() {
distributorConfig,
newSessionQueueServerConfig)))
.start();
waitUntilReady(nodeServer);
waitUntilReady(nodeServer, Duration.ofSeconds(5));

waitUntilReady(router);
waitUntilReady(router, Duration.ofSeconds(5));

return new TestData(
router,
Expand All @@ -309,13 +308,21 @@ private static TestData createFullyDistributed() {
eventServer::stop);
}

private static void waitUntilReady(Server<?> server) {
private static void waitUntilReady(Server<?> server, Duration duration) {
waitUntilReady(server, duration, false);
}

private static void waitUntilReady(Server<?> server, Duration duration, boolean printOutput) {
HttpClient client = HttpClient.Factory.createDefault().createClient(server.getUrl());

new FluentWait<>(client)
.withTimeout(Duration.ofSeconds(5))
.withTimeout(duration)
.pollingEvery(Duration.ofSeconds(1))
.until(c -> {
HttpResponse response = c.execute(new HttpRequest(GET, "/status"));
if (printOutput) {
System.out.println(Contents.string(response));
}
Map<String, Object> status = Values.get(response, MAP_TYPE);
return Boolean.TRUE.equals(status.get("ready"));
});
Expand Down Expand Up @@ -388,18 +395,7 @@ public void exerciseDriver() {
// Kill the session, and wait until the grid says it's ready
driver.quit();

HttpClient client = clientFactory.createClient(server.getUrl());
new FluentWait<>("").withTimeout(ofSeconds(200)).until(obj -> {
try {
HttpResponse response = client.execute(new HttpRequest(GET, "/status"));
System.out.println(Contents.string(response));
Map<String, Object> status = Values.get(response, MAP_TYPE);
return Boolean.TRUE.equals(status.get("ready"));
} catch (UncheckedIOException e) {
e.printStackTrace();
return false;
}
});
waitUntilReady(server, Duration.ofSeconds(200), true);

// And now we're good to go.
driver = new RemoteWebDriver(server.getUrl(), caps);
Expand Down

0 comments on commit 32d0ef7

Please sign in to comment.