2121import static java .util .concurrent .TimeUnit .MINUTES ;
2222import static org .assertj .core .api .Assertions .assertThat ;
2323import static org .junit .jupiter .api .Assertions .assertThrows ;
24- import static org .junit .jupiter .api .Assertions .assertTrue ;
2524
2625import java .io .StringReader ;
2726import java .util .LinkedList ;
@@ -77,7 +76,7 @@ public void setupServers() {
7776 + "\n "
7877 + "session-timeout = 11"
7978 + "\n "
80- + "overwrite -max-sessions = true"
79+ + "override -max-sessions = true"
8180 + "\n "
8281 + "max-sessions = "
8382 + Runtime .getRuntime ().availableProcessors () * 2
@@ -116,30 +115,26 @@ void multipleSimultaneousSessions() throws Exception {
116115 CompletableFuture <?>[] futures = new CompletableFuture <?>[10 ];
117116 for (int i = 0 ; i < futures .length ; i ++) {
118117 CompletableFuture <Object > future = new CompletableFuture <>();
119- futures [i ] = future ;
120-
121- executor .submit (
122- () -> {
123- try {
124- WebDriver driver =
125- RemoteWebDriver .builder ()
126- .oneOf (
127- browser
128- .getCapabilities ()
129- .merge (new MutableCapabilities (Map .of ("se:downloadsEnabled" , true ))))
130- .address (server .getUrl ())
131- .build ();
132-
133- driver .get (appServer .getUrl ().toString ());
134- driver .findElement (By .tagName ("body" ));
135-
136- // And now quit
137- driver .quit ();
138- future .complete (true );
139- } catch (Exception e ) {
140- future .completeExceptionally (e );
141- }
142- });
118+ futures [i ] =
119+ CompletableFuture .runAsync (
120+ () -> {
121+ WebDriver driver =
122+ RemoteWebDriver .builder ()
123+ .oneOf (
124+ browser
125+ .getCapabilities ()
126+ .merge (
127+ new MutableCapabilities (Map .of ("se:downloadsEnabled" , true ))))
128+ .address (server .getUrl ())
129+ .build ();
130+
131+ driver .get (appServer .getUrl ().toString ());
132+ driver .findElement (By .tagName ("body" ));
133+
134+ // And now quit
135+ driver .quit ();
136+ },
137+ executor );
143138 }
144139
145140 CompletableFuture .allOf (futures ).get (4 , MINUTES );
@@ -151,35 +146,48 @@ void multipleSimultaneousSessionsTimedOut() throws Exception {
151146
152147 CompletableFuture <?>[] futures = new CompletableFuture <?>[10 ];
153148 for (int i = 0 ; i < futures .length ; i ++) {
154- CompletableFuture <Object > future = new CompletableFuture <>();
155- futures [i ] = future ;
156-
157- executor .submit (
158- () -> {
159- try {
160- WebDriver driver =
161- RemoteWebDriver .builder ()
162- .oneOf (browser .getCapabilities ())
163- .address (server .getUrl ())
164- .build ();
165- driver .get (appServer .getUrl ().toString ());
166- Thread .sleep (11000 );
167- NoSuchSessionException exception =
168- assertThrows (NoSuchSessionException .class , driver ::getTitle );
169- assertTrue (exception .getMessage ().startsWith ("Cannot find session with id:" ));
170- WebDriverException webDriverException =
171- assertThrows (
172- WebDriverException .class ,
173- () -> ((RemoteWebDriver ) driver ).getDownloadableFiles ());
174- assertTrue (
175- webDriverException
176- .getMessage ()
177- .startsWith ("Cannot find downloads file system for session id:" ));
178- future .complete (true );
179- } catch (Exception e ) {
180- future .completeExceptionally (e );
181- }
182- });
149+ futures [i ] =
150+ CompletableFuture .runAsync (
151+ () -> {
152+ WebDriver driver =
153+ RemoteWebDriver .builder ()
154+ .oneOf (browser .getCapabilities ())
155+ .address (server .getUrl ())
156+ .build ();
157+ driver .get (appServer .getUrl ().toString ());
158+ try {
159+ Thread .sleep (11000 );
160+ } catch (InterruptedException ex ) {
161+ Thread .currentThread ().interrupt ();
162+ throw new RuntimeException (ex );
163+ }
164+ // note: As soon as the session cleanup of the node is performed, the grid is unable
165+ // to route the request. All commands to a session in this state will fail with:
166+ // "Unable to find session with ID:"
167+ NoSuchSessionException exception =
168+ assertThrows (NoSuchSessionException .class , driver ::getTitle );
169+ assertThat (exception .getMessage ())
170+ .matches (
171+ (msg ) ->
172+ // the session timed out, the cleanup is pending
173+ msg .startsWith ("Cannot find session with id:" )
174+ // the session timed out, the cleanup is done
175+ || msg .startsWith ("Unable to find session with ID:" ),
176+ "Cannot find session … / Unable to find session …" );
177+ WebDriverException webDriverException =
178+ assertThrows (
179+ WebDriverException .class ,
180+ () -> ((RemoteWebDriver ) driver ).getDownloadableFiles ());
181+ assertThat (webDriverException .getMessage ())
182+ .matches (
183+ (msg ) ->
184+ // the session timed out, the cleanup is pending
185+ msg .startsWith ("Cannot find downloads file system for session id:" )
186+ // the session timed out, the cleanup is done
187+ || msg .startsWith ("Unable to find session with ID:" ),
188+ "Cannot find downloads … / Unable to find session …" );
189+ },
190+ executor );
183191 }
184192
185193 CompletableFuture .allOf (futures ).get (5 , MINUTES );
0 commit comments