[java] Making router test more stable by waiting for readiness
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 java.net.URI;
import java.net.URISyntaxException;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import static org.openqa.selenium.grid.data.Availability.DOWN;
import static org.openqa.selenium.grid.data.Availability.UP;
import static org.openqa.selenium.json.Json.MAP_TYPE;
@@ -143,8 +143,7 @@ public void aNodeThatIsUpAndHasSpareSessionsMeansTheGridIsReady() throws URISynt
.build();
distributor.add(node);
- Map<String, Object> status = getStatus(router);
- assertTrue(status.toString(), (Boolean) status.get("ready"));
+ waitUntilReady(router, Duration.ofSeconds(5));
}
@Test
@@ -163,4 +162,15 @@ public void ifNodesHaveSpareSlotsButAlreadyHaveMaxSessionsGridIsNotReady() {
assertNotNull(status);
return status;
}
+
+ private static void waitUntilReady(Router router, Duration duration) {
+ new FluentWait<>(router)
+ .withTimeout(duration)
+ .pollingEvery(Duration.ofMillis(100))
+ .until(r -> {
+ HttpResponse response = r.execute(new HttpRequest(GET, "/status"));
+ Map<String, Object> status = Values.get(response, MAP_TYPE);
+ return Boolean.TRUE.equals(status.get("ready"));
+ });
+ }
}
