45
45
import org .openqa .selenium .remote .http .HttpResponse ;
46
46
import org .openqa .selenium .remote .tracing .DefaultTestTracer ;
47
47
import org .openqa .selenium .remote .tracing .Tracer ;
48
+ import org .openqa .selenium .support .ui .FluentWait ;
48
49
49
50
import java .net .URI ;
50
51
import java .net .URISyntaxException ;
55
56
56
57
import static org .junit .Assert .assertFalse ;
57
58
import static org .junit .Assert .assertNotNull ;
58
- import static org .junit .Assert .assertTrue ;
59
59
import static org .openqa .selenium .grid .data .Availability .DOWN ;
60
60
import static org .openqa .selenium .grid .data .Availability .UP ;
61
61
import static org .openqa .selenium .json .Json .MAP_TYPE ;
@@ -94,12 +94,12 @@ public void setUp() {
94
94
handler .addHandler (queuer );
95
95
96
96
distributor = new LocalDistributor (
97
- tracer ,
98
- bus ,
99
- clientFactory ,
100
- sessions ,
101
- queuer ,
102
- registrationSecret );
97
+ tracer ,
98
+ bus ,
99
+ clientFactory ,
100
+ sessions ,
101
+ queuer ,
102
+ registrationSecret );
103
103
handler .addHandler (distributor );
104
104
105
105
router = new Router (tracer , clientFactory , sessions , queuer , distributor );
@@ -119,10 +119,10 @@ public void addingANodeThatIsDownMeansTheGridIsNotReady() throws URISyntaxExcept
119
119
AtomicReference <Availability > isUp = new AtomicReference <>(DOWN );
120
120
121
121
Node node = LocalNode .builder (tracer , bus , uri , uri , registrationSecret )
122
- .add (capabilities , new TestSessionFactory ((id , caps ) -> new Session (id , uri , new ImmutableCapabilities (), caps , Instant .now ())))
123
- .advanced ()
124
- .healthCheck (() -> new HealthCheck .Result (isUp .get (), "TL;DR" ))
125
- .build ();
122
+ .add (capabilities , new TestSessionFactory ((id , caps ) -> new Session (id , uri , new ImmutableCapabilities (), caps , Instant .now ())))
123
+ .advanced ()
124
+ .healthCheck (() -> new HealthCheck .Result (isUp .get (), "TL;DR" ))
125
+ .build ();
126
126
distributor .add (node );
127
127
128
128
Map <String , Object > status = getStatus (router );
@@ -137,14 +137,13 @@ public void aNodeThatIsUpAndHasSpareSessionsMeansTheGridIsReady() throws URISynt
137
137
AtomicReference <Availability > isUp = new AtomicReference <>(UP );
138
138
139
139
Node node = LocalNode .builder (tracer , bus , uri , uri , registrationSecret )
140
- .add (capabilities , new TestSessionFactory ((id , caps ) -> new Session (id , uri , new ImmutableCapabilities (), caps , Instant .now ())))
141
- .advanced ()
142
- .healthCheck (() -> new HealthCheck .Result (isUp .get (), "TL;DR" ))
143
- .build ();
140
+ .add (capabilities , new TestSessionFactory ((id , caps ) -> new Session (id , uri , new ImmutableCapabilities (), caps , Instant .now ())))
141
+ .advanced ()
142
+ .healthCheck (() -> new HealthCheck .Result (isUp .get (), "TL;DR" ))
143
+ .build ();
144
144
distributor .add (node );
145
145
146
- Map <String , Object > status = getStatus (router );
147
- assertTrue (status .toString (), (Boolean ) status .get ("ready" ));
146
+ waitUntilReady (router , Duration .ofSeconds (5 ));
148
147
}
149
148
150
149
@ Test
@@ -163,4 +162,15 @@ private Map<String, Object> getStatus(Router router) {
163
162
assertNotNull (status );
164
163
return status ;
165
164
}
165
+
166
+ private static void waitUntilReady (Router router , Duration duration ) {
167
+ new FluentWait <>(router )
168
+ .withTimeout (duration )
169
+ .pollingEvery (Duration .ofMillis (100 ))
170
+ .until (r -> {
171
+ HttpResponse response = r .execute (new HttpRequest (GET , "/status" ));
172
+ Map <String , Object > status = Values .get (response , MAP_TYPE );
173
+ return Boolean .TRUE .equals (status .get ("ready" ));
174
+ });
175
+ }
166
176
}
0 commit comments