@@ -170,7 +170,7 @@ private void waitUntilAddedToQueue(SessionRequest request) {
170
170
@ MethodSource ("data" )
171
171
void shouldBeAbleToAddToQueueAndGetValidResponse (Supplier <TestData > supplier ) {
172
172
setup (supplier );
173
-
173
+
174
174
AtomicBoolean isPresent = new AtomicBoolean (false );
175
175
176
176
new Thread (
@@ -207,6 +207,118 @@ void shouldBeAbleToAddToQueueAndGetValidResponse(Supplier<TestData> supplier) {
207
207
assertThat (isPresent .get ()).isTrue ();
208
208
assertEquals (HTTP_OK , httpResponse .getStatus ());
209
209
}
210
+
211
+
212
+ @ ParameterizedTest
213
+ @ MethodSource ("data" )
214
+ void shouldBeAbleToAddToQueueWithTimeoutAndGetValidResponse (Supplier <TestData > supplier ) {
215
+ setup (supplier );
216
+
217
+ SessionRequest sessionRequestWithTimeout = new SessionRequest (
218
+ new RequestId (UUID .randomUUID ()),
219
+ Instant .now (),
220
+ Set .of (W3C ),
221
+ Set .of (CAPS ),
222
+ Map .of (),
223
+ Map .of ());
224
+
225
+ AtomicBoolean isPresent = new AtomicBoolean (false );
226
+
227
+ new Thread (() -> {
228
+ waitUntilAddedToQueue (sessionRequestWithTimeout );
229
+ isPresent .set (true );
230
+
231
+ Capabilities capabilities = new ImmutableCapabilities ("browserName" , "chrome" );
232
+
233
+ try {
234
+ Thread .sleep (4000 ); // simulate session waiting in queue
235
+ } catch (InterruptedException e ) {}
236
+
237
+ // remove request from queue
238
+ Map <Capabilities , Long > stereotypes = new HashMap <>();
239
+ stereotypes .put (new ImmutableCapabilities ("browserName" , "cheese" ), 1L );
240
+ List <SessionRequest > requests = queue .getNextAvailable (stereotypes );
241
+
242
+ SessionId sessionId = new SessionId ("123" );
243
+ Session session =
244
+ new Session (
245
+ sessionId ,
246
+ URI .create ("https://example.com" ),
247
+ CAPS ,
248
+ capabilities ,
249
+ Instant .now ());
250
+ CreateSessionResponse sessionResponse = new CreateSessionResponse (
251
+ session ,
252
+ JSON .toJson (
253
+ ImmutableMap .of (
254
+ "value" , ImmutableMap .of (
255
+ "sessionId" , sessionId ,
256
+ "capabilities" , capabilities )))
257
+ .getBytes (UTF_8 ));
258
+
259
+ try {
260
+ Thread .sleep (2000 ); // simulate session creation delay
261
+ } catch (InterruptedException e ) {}
262
+ queue .complete (sessionRequestWithTimeout .getRequestId (), Either .right (sessionResponse ));
263
+ }).start ();
264
+
265
+ HttpResponse httpResponse = queue .addToQueue (sessionRequestWithTimeout );
266
+
267
+ assertThat (isPresent .get ()).isTrue ();
268
+ assertEquals (HTTP_OK , httpResponse .getStatus ());
269
+ }
270
+
271
+
272
+ @ ParameterizedTest
273
+ @ MethodSource ("data" )
274
+ void shouldBeAbleToAddToQueueWithTimeoutAndTimeoutResponse (Supplier <TestData > supplier ) {
275
+ setup (supplier );
276
+
277
+ SessionRequest sessionRequestWithTimeout = new SessionRequest (
278
+ new RequestId (UUID .randomUUID ()),
279
+ Instant .now (),
280
+ Set .of (W3C ),
281
+ Set .of (CAPS ),
282
+ Map .of (),
283
+ Map .of ());
284
+
285
+ AtomicBoolean isPresent = new AtomicBoolean (false );
286
+
287
+ new Thread (() -> {
288
+ waitUntilAddedToQueue (sessionRequestWithTimeout );
289
+ isPresent .set (true );
290
+
291
+ Capabilities capabilities = new ImmutableCapabilities ("browserName" , "chrome" );
292
+
293
+ try {
294
+ Thread .sleep (5500 ); // simulate session waiting in queue
295
+ } catch (InterruptedException e ) {}
296
+
297
+ SessionId sessionId = new SessionId ("123" );
298
+ Session session =
299
+ new Session (
300
+ sessionId ,
301
+ URI .create ("https://example.com" ),
302
+ CAPS ,
303
+ capabilities ,
304
+ Instant .now ());
305
+ CreateSessionResponse sessionResponse = new CreateSessionResponse (
306
+ session ,
307
+ JSON .toJson (
308
+ ImmutableMap .of (
309
+ "value" , ImmutableMap .of (
310
+ "sessionId" , sessionId ,
311
+ "capabilities" , capabilities )))
312
+ .getBytes (UTF_8 ));
313
+
314
+ queue .complete (sessionRequestWithTimeout .getRequestId (), Either .right (sessionResponse ));
315
+ }).start ();
316
+
317
+ HttpResponse httpResponse = queue .addToQueue (sessionRequestWithTimeout );
318
+
319
+ assertThat (isPresent .get ()).isTrue ();
320
+ assertEquals (HTTP_INTERNAL_ERROR , httpResponse .getStatus ());
321
+ }
210
322
211
323
@ ParameterizedTest
212
324
@ MethodSource ("data" )
0 commit comments