2424import java .util .List ;
2525import java .util .Map ;
2626import java .util .Objects ;
27+ import java .util .concurrent .CompletableFuture ;
2728import java .util .concurrent .CountDownLatch ;
2829import java .util .concurrent .ExecutorService ;
2930import java .util .concurrent .Executors ;
3031import java .util .concurrent .Future ;
3132import java .util .concurrent .TimeUnit ;
3233import java .util .function .Supplier ;
3334import org .assertj .core .api .Assertions ;
34- import org .junit .jupiter .api .Disabled ;
3535import org .junit .jupiter .api .Test ;
3636import org .openqa .selenium .WebDriver ;
3737import org .openqa .selenium .grid .commands .Hub ;
@@ -52,7 +52,6 @@ class DrainTest {
5252
5353 private final Browser browser = Objects .requireNonNull (Browser .detect ());
5454
55- @ Disabled ("will be fixed with PR 14987" )
5655 @ Test
5756 void nodeDoesNotTakeTooManySessions () throws Exception {
5857 String [] rawConfig =
@@ -105,7 +104,7 @@ void nodeDoesNotTakeTooManySessions() throws Exception {
105104 assertThat (pendingSessions .removeIf (Future ::isDone )).isEqualTo (i != 0 );
106105
107106 // start a node draining after 3 sessions
108- var node = startNode (baseConfig , hub , 6 , 3 );
107+ Server <?> node = startNode (baseConfig , hub , 6 , 3 );
109108
110109 urlChecker .waitUntilAvailable (
111110 20 , TimeUnit .SECONDS , node .getUrl ().toURI ().resolve ("readyz" ).toURL ());
@@ -115,7 +114,7 @@ void nodeDoesNotTakeTooManySessions() throws Exception {
115114 int stopped = 0 ;
116115
117116 for (int j = 0 ; j < pendingSessions .size (); j ++) {
118- var future = pendingSessions .get (j );
117+ Future < WebDriver > future = pendingSessions .get (j );
119118
120119 if (future .isDone ()) {
121120 stopped ++;
@@ -159,30 +158,26 @@ void sessionIsNotRejectedWhenNodeDrains() throws Exception {
159158
160159 ExecutorService executor = Executors .newFixedThreadPool (2 );
161160
162- Supplier <Future <WebDriver >> newDriver =
163- () ->
164- executor .submit (
165- () ->
166- RemoteWebDriver .builder ()
167- .oneOf (browser .getCapabilities ())
168- .address (hub .getUrl ())
169- .build ());
170-
171161 try {
172- Future <WebDriver > pendingA = newDriver .get ();
173- Future <WebDriver > pendingB = newDriver .get ();
162+ Supplier <CompletableFuture <WebDriver >> newDriver =
163+ () ->
164+ CompletableFuture .supplyAsync (
165+ () ->
166+ RemoteWebDriver .builder ()
167+ .oneOf (browser .getCapabilities ())
168+ .address (hub .getUrl ())
169+ .build (),
170+ executor );
171+
172+ CompletableFuture <WebDriver > pendingA = newDriver .get ();
173+ CompletableFuture <WebDriver > pendingB = newDriver .get ();
174174
175175 for (int i = 0 ; i < 16 ; i ++) {
176- // the node should drain automatically
176+ // the node should drain automatically, covered by other tests
177177 startNode (baseConfig , hub , 6 , 1 );
178178
179- for (int j = 0 ; j < 2000 ; j ++) {
180- Thread .sleep (10 );
181-
182- if (pendingA .isDone () || pendingB .isDone ()) {
183- break ;
184- }
185- }
179+ // wait for one to start
180+ CompletableFuture .anyOf (pendingA , pendingB ).get (80 , TimeUnit .SECONDS );
186181
187182 if (pendingA .isDone () && pendingB .isDone ()) {
188183 pendingA .get ().quit ();
@@ -195,8 +190,6 @@ void sessionIsNotRejectedWhenNodeDrains() throws Exception {
195190 } else if (pendingB .isDone ()) {
196191 pendingB .get ().quit ();
197192 pendingB = newDriver .get ();
198- } else {
199- throw new IllegalStateException ("no browser started" );
200193 }
201194 }
202195 } finally {
0 commit comments