54
54
import org .eclipse .jetty .util .FuturePromise ;
55
55
import org .eclipse .jetty .util .IO ;
56
56
import org .eclipse .jetty .util .ssl .SslContextFactory ;
57
+ import org .hamcrest .Matchers ;
57
58
import org .junit .jupiter .api .Assumptions ;
58
59
import org .junit .jupiter .params .ParameterizedTest ;
59
60
import org .junit .jupiter .params .provider .ArgumentsSource ;
60
61
import org .opentest4j .TestAbortedException ;
61
62
62
63
import static org .eclipse .jetty .http .client .Transport .UNIX_SOCKET ;
64
+ import static org .hamcrest .MatcherAssert .assertThat ;
63
65
import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
64
66
import static org .junit .jupiter .api .Assertions .assertEquals ;
65
67
import static org .junit .jupiter .api .Assertions .assertFalse ;
@@ -501,6 +503,83 @@ protected void service(String target, org.eclipse.jetty.server.Request jettyRequ
501
503
assertTrue (latch .await (5 , TimeUnit .SECONDS ));
502
504
}
503
505
506
+ @ ParameterizedTest
507
+ @ ArgumentsSource (TransportProvider .class )
508
+ public void testRequestQueuedDoesNotCancelTimeoutOfQueuedRequests (Transport transport ) throws Exception
509
+ {
510
+ init (transport );
511
+
512
+ CountDownLatch serverLatch = new CountDownLatch (1 );
513
+ scenario .start (new EmptyServerHandler ()
514
+ {
515
+ @ Override
516
+ protected void service (String target , org .eclipse .jetty .server .Request jettyRequest , HttpServletRequest request , HttpServletResponse response ) throws IOException
517
+ {
518
+ if (request .getRequestURI ().startsWith ("/one" ))
519
+ {
520
+ try
521
+ {
522
+ serverLatch .await ();
523
+ }
524
+ catch (InterruptedException x )
525
+ {
526
+ throw new InterruptedIOException ();
527
+ }
528
+ }
529
+ }
530
+ });
531
+
532
+ scenario .client .setMaxConnectionsPerDestination (1 );
533
+ scenario .setMaxRequestsPerConnection (1 );
534
+
535
+ // Send the first request so that the others get queued.
536
+ CountDownLatch latch1 = new CountDownLatch (1 );
537
+ scenario .client .newRequest (scenario .newURI ())
538
+ .path ("/one" )
539
+ .send (result ->
540
+ {
541
+ assertTrue (result .isSucceeded ());
542
+ assertEquals (HttpStatus .OK_200 , result .getResponse ().getStatus ());
543
+ latch1 .countDown ();
544
+ });
545
+
546
+ // Queue a second request, it should expire in the queue.
547
+ long timeout = 1000 ;
548
+ CountDownLatch latch2 = new CountDownLatch (1 );
549
+ scenario .client .newRequest (scenario .newURI ())
550
+ .path ("/two" )
551
+ .timeout (2 * timeout , TimeUnit .MILLISECONDS )
552
+ .send (result ->
553
+ {
554
+ assertTrue (result .isFailed ());
555
+ assertThat (result .getFailure (), Matchers .instanceOf (TimeoutException .class ));
556
+ latch2 .countDown ();
557
+ });
558
+
559
+ Thread .sleep (timeout );
560
+
561
+ // Queue a third request, it should not reset the timeout of the second request.
562
+ CountDownLatch latch3 = new CountDownLatch (1 );
563
+ scenario .client .newRequest (scenario .newURI ())
564
+ .path ("/three" )
565
+ .timeout (2 * timeout , TimeUnit .MILLISECONDS )
566
+ .send (result ->
567
+ {
568
+ assertTrue (result .isSucceeded ());
569
+ assertEquals (HttpStatus .OK_200 , result .getResponse ().getStatus ());
570
+ latch3 .countDown ();
571
+ });
572
+
573
+ // We have already slept a timeout, expect the second request to be back in another timeout.
574
+ assertTrue (latch2 .await (2 * timeout , TimeUnit .MILLISECONDS ));
575
+
576
+ // Release the first request so the third can be served as well.
577
+ serverLatch .countDown ();
578
+
579
+ assertTrue (latch1 .await (2 * timeout , TimeUnit .MILLISECONDS ));
580
+ assertTrue (latch3 .await (2 * timeout , TimeUnit .MILLISECONDS ));
581
+ }
582
+
504
583
private void assumeConnectTimeout (String host , int port , int connectTimeout )
505
584
{
506
585
try (Socket socket = new Socket ())
@@ -516,7 +595,6 @@ private void assumeConnectTimeout(String host, int port, int connectTimeout)
516
595
catch (SocketTimeoutException x )
517
596
{
518
597
// Expected timeout during connect, continue the test.
519
- return ;
520
598
}
521
599
catch (Throwable x )
522
600
{
@@ -525,7 +603,7 @@ private void assumeConnectTimeout(String host, int port, int connectTimeout)
525
603
}
526
604
}
527
605
528
- private class TimeoutHandler extends AbstractHandler
606
+ private static class TimeoutHandler extends AbstractHandler
529
607
{
530
608
private final long timeout ;
531
609
0 commit comments