File tree Expand file tree Collapse file tree
src/org/openqa/selenium/grid/router
test/org/openqa/selenium/grid/router Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4040import java .util .concurrent .Executors ;
4141import java .util .concurrent .TimeoutException ;
4242
43+ import static java .net .HttpURLConnection .HTTP_UNAVAILABLE ;
4344import static java .util .concurrent .TimeUnit .SECONDS ;
4445import static java .util .stream .Collectors .toList ;
4546import static org .openqa .selenium .grid .data .Availability .UP ;
@@ -145,10 +146,15 @@ public HttpResponse execute(HttpRequest req) {
145146
146147 HttpResponse res = new HttpResponse ()
147148 .setContent (asJson (ImmutableMap .of ("value" , value .build ())));
149+ if (ready ) {
150+ span .setStatus (Status .OK );
151+ } else {
152+ res .setStatus (HTTP_UNAVAILABLE );
153+ span .setStatus (Status .UNAVAILABLE );
154+ }
148155 HTTP_RESPONSE .accept (span , res );
149156 HTTP_RESPONSE_EVENT .accept (attributeMap , res );
150157 attributeMap .put ("grid.status" , EventAttribute .setValue (ready ));
151- span .setStatus (Status .OK );
152158 span .addEvent ("Computed grid status" , attributeMap );
153159 return res ;
154160 }
Original file line number Diff line number Diff line change 1717
1818package org .openqa .selenium .grid .router ;
1919
20+ import static org .junit .Assert .assertEquals ;
2021import static org .junit .Assert .assertFalse ;
2122import static org .junit .Assert .assertNotNull ;
2223import static org .openqa .selenium .grid .data .Availability .DOWN ;
@@ -128,6 +129,13 @@ public void shouldListAnEmptyDistributorAsMeaningTheGridIsNotReady() {
128129 assertFalse ((Boolean ) status .get ("ready" ));
129130 }
130131
132+ @ Test
133+ public void shouldReturnServerErrorCodeWhenGridIsNotReady () {
134+ HttpResponse response = getStatusHttpResponse (router );
135+ assertNotNull (response );
136+ assertEquals (503 , response .getStatus ());
137+ }
138+
131139 @ Test
132140 public void addingANodeThatIsDownMeansTheGridIsNotReady () throws URISyntaxException {
133141 Capabilities capabilities = new ImmutableCapabilities ("cheese" , "peas" );
@@ -179,4 +187,8 @@ private Map<String, Object> getStatus(Router router) {
179187 assertNotNull (status );
180188 return status ;
181189 }
190+
191+ private HttpResponse getStatusHttpResponse (Router router ) {
192+ return router .execute (new HttpRequest (GET , "/status" ));
193+ }
182194}
You can’t perform that action at this time.
0 commit comments