|
29 | 29 | import org.openqa.selenium.MutableCapabilities; |
30 | 30 | import org.openqa.selenium.NoSuchSessionException; |
31 | 31 | import org.openqa.selenium.SessionNotCreatedException; |
32 | | -import org.openqa.selenium.TimeoutException; |
33 | 32 | import org.openqa.selenium.events.EventBus; |
34 | 33 | import org.openqa.selenium.events.local.GuavaEventBus; |
35 | 34 | import org.openqa.selenium.grid.data.Availability; |
@@ -119,7 +118,7 @@ private static <A, B> EitherAssert<A, B> assertThatEither(Either<A, B> either) { |
119 | 118 | @Before |
120 | 119 | public void setUp() throws URISyntaxException { |
121 | 120 | nodeUri = new URI("http://example:5678"); |
122 | | - routableUri = new URI(String.format("http://localhost:%s", PortProber.findFreePort())); |
| 121 | + routableUri = createUri(); |
123 | 122 | tracer = DefaultTestTracer.createTracer(); |
124 | 123 | bus = new GuavaEventBus(); |
125 | 124 | LocalSessionMap sessions = new LocalSessionMap(tracer, bus); |
@@ -198,7 +197,7 @@ public void shouldStartHeartBeatOnNodeRegistration() { |
198 | 197 | } |
199 | 198 |
|
200 | 199 | assertThat(eventFired).isTrue(); |
201 | | - assertThat(heartbeatStarted).isTrue(); |
| 200 | + assertThat(heartbeatStarted.get()).isTrue(); |
202 | 201 | } |
203 | 202 |
|
204 | 203 | @Test |
@@ -559,6 +558,8 @@ public void theMostLightlyLoadedNodeIsSelectedFirst() { |
559 | 558 | .add(massive); |
560 | 559 |
|
561 | 560 | wait.until(obj -> distributor.getStatus().getNodes().size() == 4); |
| 561 | + wait.until(ignored -> distributor.getStatus().getNodes().stream().allMatch( |
| 562 | + node -> node.getAvailability() == UP && node.hasCapacity())); |
562 | 563 | wait.until(obj -> distributor.getStatus().hasCapacity()); |
563 | 564 |
|
564 | 565 | Either<SessionNotCreatedException, CreateSessionResponse> result = |
@@ -684,10 +685,11 @@ public void shouldIncludeHostsThatAreUpInHostList() { |
684 | 685 | queue, |
685 | 686 | new DefaultSlotSelector(), |
686 | 687 | registrationSecret, |
687 | | - Duration.ofMinutes(5), |
| 688 | + Duration.ofSeconds(1), |
688 | 689 | false); |
689 | 690 | handler.addHandler(distributor); |
690 | 691 | distributor.add(alwaysDown); |
| 692 | + waitForAllNodesToMeetCondition(distributor, 1, DOWN); |
691 | 693 |
|
692 | 694 | // Should be unable to create a session because the node is down. |
693 | 695 | Either<SessionNotCreatedException, CreateSessionResponse> result = |
@@ -904,10 +906,11 @@ public void shouldReturnNodesThatWereDownToPoolOfNodesOnceTheyMarkTheirHealthChe |
904 | 906 | queue, |
905 | 907 | new DefaultSlotSelector(), |
906 | 908 | registrationSecret, |
907 | | - Duration.ofMinutes(5), |
| 909 | + Duration.ofSeconds(1), |
908 | 910 | false); |
909 | 911 | handler.addHandler(distributor); |
910 | 912 | distributor.add(node); |
| 913 | + waitForAllNodesToMeetCondition(distributor, 1, DOWN); |
911 | 914 |
|
912 | 915 | // Should be unable to create a session because the node is down. |
913 | 916 | Either<SessionNotCreatedException, CreateSessionResponse> result = |
@@ -1131,7 +1134,7 @@ public void shouldFallbackToSecondAvailableCapabilitiesIfFirstNotAvailable() { |
1131 | 1134 | public void shouldFallbackToSecondAvailableCapabilitiesIfFirstThrowsOnCreation() { |
1132 | 1135 | local.add(createBrokenNode(new ImmutableCapabilities("browserName", "not cheese"))); |
1133 | 1136 | local.add(createNode(new ImmutableCapabilities("browserName", "cheese"), 1, 0)); |
1134 | | - waitToHaveCapacity(local); |
| 1137 | + waitForAllNodesToHaveCapacity(local, 2); |
1135 | 1138 |
|
1136 | 1139 | SessionRequest sessionRequest = new SessionRequest( |
1137 | 1140 | new RequestId(UUID.randomUUID()), |
@@ -1179,21 +1182,19 @@ private void waitToHaveCapacity(Distributor distributor) { |
1179 | 1182 | } |
1180 | 1183 |
|
1181 | 1184 | private void waitForAllNodesToHaveCapacity(Distributor distributor, int nodeCount) { |
1182 | | - try { |
1183 | | - new FluentWait<>(distributor) |
1184 | | - .withTimeout(Duration.ofSeconds(5)) |
1185 | | - .pollingEvery(Duration.ofMillis(100)) |
1186 | | - .until(d -> { |
1187 | | - Set<NodeStatus> nodes = d.getStatus().getNodes(); |
1188 | | - return nodes.size() == nodeCount && nodes.stream().allMatch( |
1189 | | - node -> node.getAvailability() == UP && node.hasCapacity()); |
1190 | | - }); |
1191 | | - } catch (TimeoutException ex) { |
1192 | | - Set<NodeStatus> nodes = distributor.getStatus().getNodes(); |
1193 | | - System.out.println("*************"); |
1194 | | - System.out.println("" + nodes.size()); |
1195 | | - nodes.forEach(node -> System.out.println("" + node.hasCapacity())); |
1196 | | - } |
| 1185 | + waitForAllNodesToMeetCondition(distributor, nodeCount, UP); |
| 1186 | + } |
| 1187 | + |
| 1188 | + private void waitForAllNodesToMeetCondition(Distributor distributor, int nodeCount, |
| 1189 | + Availability availability) { |
| 1190 | + new FluentWait<>(distributor) |
| 1191 | + .withTimeout(Duration.ofSeconds(5)) |
| 1192 | + .pollingEvery(Duration.ofMillis(100)) |
| 1193 | + .until(d -> { |
| 1194 | + Set<NodeStatus> nodes = d.getStatus().getNodes(); |
| 1195 | + return nodes.size() == nodeCount && nodes.stream().allMatch( |
| 1196 | + node -> node.getAvailability() == availability && node.hasCapacity()); |
| 1197 | + }); |
1197 | 1198 | } |
1198 | 1199 |
|
1199 | 1200 | class HandledSession extends Session implements HttpHandler { |
|
0 commit comments