@@ -12,7 +12,8 @@ use futures_channel::{mpsc, oneshot};
12
12
use futures_util:: future:: { self , FutureExt , TryFutureExt } ;
13
13
use futures_util:: stream:: StreamExt ;
14
14
use futures_util:: { self , Stream } ;
15
- use http_body_util:: { BodyStream , Empty , Full } ;
15
+ use http_body_util:: BodyExt ;
16
+ use http_body_util:: { Empty , Full } ;
16
17
17
18
use hyper:: body:: Bytes ;
18
19
use hyper:: Request ;
@@ -148,6 +149,7 @@ async fn drop_client_closes_idle_connections() {
148
149
future:: select ( t, close) . await ;
149
150
}
150
151
152
+ #[ cfg( not( miri) ) ]
151
153
#[ tokio:: test]
152
154
async fn drop_response_future_closes_in_progress_connection ( ) {
153
155
let _ = pretty_env_logger:: try_init ( ) ;
@@ -196,6 +198,7 @@ async fn drop_response_future_closes_in_progress_connection() {
196
198
future:: select ( t, close) . await ;
197
199
}
198
200
201
+ #[ cfg( not( miri) ) ]
199
202
#[ tokio:: test]
200
203
async fn drop_response_body_closes_in_progress_connection ( ) {
201
204
let _ = pretty_env_logger:: try_init ( ) ;
@@ -251,6 +254,7 @@ async fn drop_response_body_closes_in_progress_connection() {
251
254
future:: select ( t, close) . await ;
252
255
}
253
256
257
+ #[ cfg( not( miri) ) ]
254
258
#[ tokio:: test]
255
259
async fn no_keep_alive_closes_connection ( ) {
256
260
// https://github.com/hyperium/hyper/issues/1383
@@ -303,6 +307,7 @@ async fn no_keep_alive_closes_connection() {
303
307
future:: select ( close, t) . await ;
304
308
}
305
309
310
+ #[ cfg( not( miri) ) ]
306
311
#[ tokio:: test]
307
312
async fn socket_disconnect_closes_idle_conn ( ) {
308
313
// notably when keep-alive is enabled
@@ -349,6 +354,7 @@ async fn socket_disconnect_closes_idle_conn() {
349
354
future:: select ( t, close) . await ;
350
355
}
351
356
357
+ #[ cfg( not( miri) ) ]
352
358
#[ test]
353
359
fn connect_call_is_lazy ( ) {
354
360
// We especially don't want connects() triggered if there's
@@ -372,6 +378,7 @@ fn connect_call_is_lazy() {
372
378
assert_eq ! ( connects. load( Ordering :: Relaxed ) , 0 ) ;
373
379
}
374
380
381
+ #[ cfg( not( miri) ) ]
375
382
#[ test]
376
383
fn client_keep_alive_0 ( ) {
377
384
let _ = pretty_env_logger:: try_init ( ) ;
@@ -438,6 +445,7 @@ fn client_keep_alive_0() {
438
445
drop ( client) ;
439
446
}
440
447
448
+ #[ cfg( not( miri) ) ]
441
449
#[ test]
442
450
fn client_keep_alive_extra_body ( ) {
443
451
let _ = pretty_env_logger:: try_init ( ) ;
@@ -509,8 +517,9 @@ fn client_keep_alive_extra_body() {
509
517
//
510
518
// let connector = DebugConnector::new();
511
519
// let connects = connector.connects.clone();
520
+ // let executor = TokioExecutor::new();
512
521
//
513
- // let client = Client::builder(TokioExecutor::new ()).build(connector);
522
+ // let client = Client::builder(executor.clone ()).build(connector.clone() );
514
523
//
515
524
// let (tx1, rx1) = oneshot::channel();
516
525
// let (tx2, rx2) = oneshot::channel();
@@ -542,126 +551,128 @@ fn client_keep_alive_extra_body() {
542
551
// assert_eq!(connects.load(Ordering::Relaxed), 0);
543
552
//
544
553
// let delayed_body = rx1
545
- // .then(|_| tokio::time::sleep(Duration::from_millis(200)))
546
- // .map(|_| Ok::<_, ()>("hello a"))
554
+ // .then(|_| Box::pin( tokio::time::sleep(Duration::from_millis(200) )))
555
+ // .map(|_| Ok::<_, ()>(Frame::data(&b "hello a"[..]) ))
547
556
// .map_err(|_| -> hyper::Error { panic!("rx1") })
548
557
// .into_stream();
549
558
//
550
- // let rx = rx2;
551
559
// let req = Request::builder()
552
560
// .method("POST")
553
561
// .uri(&*format!("http://{}/a", addr))
554
- // .body(BodyStream ::new(delayed_body))
562
+ // .body(StreamBody ::new(delayed_body))
555
563
// .unwrap();
556
- // let client2 = client.clone();
557
- //
564
+ // let client2 = Client::builder(executor.clone()).build(connector.clone());
565
+ // let res = client.request(req).map_ok(move |res| {
566
+ // assert_eq!(res.status(), hyper::StatusCode::OK);
567
+ // });
558
568
// // req 1
559
- // let fut = future::join(client.request(req), rx )
569
+ // let fut = future::join(res, rx2 )
560
570
// .then(|_| tokio::time::sleep(Duration::from_millis(200)))
561
- // // req 2
571
+ // // req 2
562
572
// .then(move |()| {
563
- // let rx = rx3.expect("thread panicked") ;
573
+ // let rx = rx3;
564
574
// let req = Request::builder()
565
575
// .uri(&*format!("http://{}/b", addr))
566
576
// .body(Empty::<Bytes>::new())
567
577
// .unwrap();
568
- // future::join(client2.request(req), rx).map(|r| r.0)
578
+ // let res = client2.request(req).map_ok(move |res| {
579
+ // assert_eq!(res.status(), hyper::StatusCode::OK);
580
+ // });
581
+ // future::join(res, rx).map(|r| r.0)
569
582
// });
570
583
//
571
584
// rt.block_on(fut).unwrap();
572
585
//
573
586
// assert_eq!(connects.load(Ordering::Relaxed), 1);
574
587
// }
575
588
576
- // #[tokio::test]
577
- // async fn client_keep_alive_eager_when_chunked() {
578
- // // If a response body has been read to completion, with completion
579
- // // determined by some other factor, like decompression, and thus
580
- // // it is in't polled a final time to clear the final 0-len chunk,
581
- // // try to eagerly clear it so the connection can still be used.
582
- //
583
- // let _ = pretty_env_logger::try_init();
584
- // let server = TcpListener::bind("127.0.0.1:0").unwrap();
585
- // let addr = server.local_addr().unwrap();
586
- // let connector = DebugConnector::new();
587
- // let connects = connector.connects.clone();
588
- //
589
- // let client = Client::builder(TokioExecutor::new()).build(connector);
590
- //
591
- // let (tx1, rx1) = oneshot::channel();
592
- // let (tx2, rx2) = oneshot::channel();
593
- // thread::spawn(move || {
594
- // let mut sock = server.accept().unwrap().0;
595
- // //drop(server);
596
- // sock.set_read_timeout(Some(Duration::from_secs(5))).unwrap();
597
- // sock.set_write_timeout(Some(Duration::from_secs(5)))
598
- // .unwrap();
599
- // let mut buf = [0; 4096];
600
- // sock.read(&mut buf).expect("read 1");
601
- // sock.write_all(
602
- // b"\
603
- // HTTP/1.1 200 OK\r\n\
604
- // transfer-encoding: chunked\r\n\
605
- // \r\n\
606
- // 5\r\n\
607
- // hello\r\n\
608
- // 0\r\n\r\n\
609
- // ",
610
- // )
611
- // .expect("write 1");
612
- // let _ = tx1.send(());
613
- //
614
- // let n2 = sock.read(&mut buf).expect("read 2");
615
- // assert_ne!(n2, 0, "bytes of second request");
616
- // let second_get = "GET /b HTTP/1.1\r\n";
617
- // assert_eq!(s(&buf[..second_get.len()]), second_get);
618
- // sock.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n")
619
- // .expect("write 2");
620
- // let _ = tx2.send(());
621
- // });
622
- //
623
- // assert_eq!(connects.load(Ordering::SeqCst), 0);
624
- //
625
- // let rx = rx1;
626
- // let req = Request::builder()
627
- // .uri(&*format!("http://{}/a", addr))
628
- // .body(Empty::<Bytes>::new())
629
- // .unwrap();
630
- // let fut = client.request(req);
631
- //
632
- // let mut resp = future::join(fut, rx).map(|r| r.0).await.unwrap();
633
- // assert_eq!(connects.load(Ordering::SeqCst), 1);
634
- // assert_eq!(resp.status(), 200);
635
- // assert_eq!(resp.headers()["transfer-encoding"], "chunked");
636
- //
637
- // // Read the "hello" chunk...
638
- // let chunk = resp.body_mut().data().await.unwrap().unwrap();
639
- // assert_eq!(chunk, "hello");
640
- //
641
- // // With our prior knowledge, we know that's the end of the body.
642
- // // So just drop the body, without polling for the `0\r\n\r\n` end.
643
- // drop(resp);
644
- //
645
- // // sleep real quick to let the threadpool put connection in ready
646
- // // state and back into client pool
647
- // tokio::time::sleep(Duration::from_millis(50)).await;
648
- //
649
- // let rx = rx2;
650
- // let req = Request::builder()
651
- // .uri(&*format!("http://{}/b", addr))
652
- // .body(Empty::<Bytes>::new())
653
- // .unwrap();
654
- // let fut = client.request(req);
655
- // future::join(fut, rx).map(|r| r.0).await.unwrap();
656
- //
657
- // assert_eq!(
658
- // connects.load(Ordering::SeqCst),
659
- // 1,
660
- // "second request should still only have 1 connect"
661
- // );
662
- // drop(client);
663
- // }
589
+ #[ cfg( not( miri) ) ]
590
+ #[ tokio:: test]
591
+ async fn client_keep_alive_eager_when_chunked ( ) {
592
+ // If a response body has been read to completion, with completion
593
+ // determined by some other factor, like decompression, and thus
594
+ // it is in't polled a final time to clear the final 0-len chunk,
595
+ // try to eagerly clear it so the connection can still be used.
596
+
597
+ let _ = pretty_env_logger:: try_init ( ) ;
598
+ let server = TcpListener :: bind ( "127.0.0.1:0" ) . unwrap ( ) ;
599
+ let addr = server. local_addr ( ) . unwrap ( ) ;
600
+ let connector = DebugConnector :: new ( ) ;
601
+ let connects = connector. connects . clone ( ) ;
602
+
603
+ let client = Client :: builder ( TokioExecutor :: new ( ) ) . build ( connector) ;
604
+
605
+ let ( tx1, rx1) = oneshot:: channel ( ) ;
606
+ let ( tx2, rx2) = oneshot:: channel ( ) ;
607
+ thread:: spawn ( move || {
608
+ let mut sock = server. accept ( ) . unwrap ( ) . 0 ;
609
+ //drop(server);
610
+ sock. set_read_timeout ( Some ( Duration :: from_secs ( 5 ) ) ) . unwrap ( ) ;
611
+ sock. set_write_timeout ( Some ( Duration :: from_secs ( 5 ) ) )
612
+ . unwrap ( ) ;
613
+ let mut buf = [ 0 ; 4096 ] ;
614
+ sock. read ( & mut buf) . expect ( "read 1" ) ;
615
+ sock. write_all (
616
+ b"\
617
+ HTTP/1.1 200 OK\r \n \
618
+ transfer-encoding: chunked\r \n \
619
+ \r \n \
620
+ 5\r \n \
621
+ hello\r \n \
622
+ 0\r \n \r \n \
623
+ ",
624
+ )
625
+ . expect ( "write 1" ) ;
626
+ let _ = tx1. send ( ( ) ) ;
627
+
628
+ let n2 = sock. read ( & mut buf) . expect ( "read 2" ) ;
629
+ assert_ne ! ( n2, 0 , "bytes of second request" ) ;
630
+ let second_get = "GET /b HTTP/1.1\r \n " ;
631
+ assert_eq ! ( s( & buf[ ..second_get. len( ) ] ) , second_get) ;
632
+ sock. write_all ( b"HTTP/1.1 200 OK\r \n Content-Length: 0\r \n \r \n " )
633
+ . expect ( "write 2" ) ;
634
+ let _ = tx2. send ( ( ) ) ;
635
+ } ) ;
636
+
637
+ assert_eq ! ( connects. load( Ordering :: SeqCst ) , 0 ) ;
638
+
639
+ let rx = rx1;
640
+ let req = Request :: builder ( )
641
+ . uri ( & * format ! ( "http://{}/a" , addr) )
642
+ . body ( Empty :: < Bytes > :: new ( ) )
643
+ . unwrap ( ) ;
644
+ let fut = client. request ( req) ;
645
+
646
+ let mut resp = future:: join ( fut, rx) . map ( |r| r. 0 ) . await . unwrap ( ) ;
647
+ assert_eq ! ( connects. load( Ordering :: SeqCst ) , 1 ) ;
648
+ assert_eq ! ( resp. status( ) , 200 ) ;
649
+ assert_eq ! ( resp. headers( ) [ "transfer-encoding" ] , "chunked" ) ;
650
+
651
+ // Read the "hello" chunk...
652
+ let chunk = resp. collect ( ) . await . unwrap ( ) . to_bytes ( ) ;
653
+ assert_eq ! ( chunk, "hello" ) ;
664
654
655
+ // sleep real quick to let the threadpool put connection in ready
656
+ // state and back into client pool
657
+ tokio:: time:: sleep ( Duration :: from_millis ( 50 ) ) . await ;
658
+
659
+ let rx = rx2;
660
+ let req = Request :: builder ( )
661
+ . uri ( & * format ! ( "http://{}/b" , addr) )
662
+ . body ( Empty :: < Bytes > :: new ( ) )
663
+ . unwrap ( ) ;
664
+ let fut = client. request ( req) ;
665
+ future:: join ( fut, rx) . map ( |r| r. 0 ) . await . unwrap ( ) ;
666
+
667
+ assert_eq ! (
668
+ connects. load( Ordering :: SeqCst ) ,
669
+ 1 ,
670
+ "second request should still only have 1 connect"
671
+ ) ;
672
+ drop ( client) ;
673
+ }
674
+
675
+ #[ cfg( not( miri) ) ]
665
676
#[ test]
666
677
fn connect_proxy_sends_absolute_uri ( ) {
667
678
let _ = pretty_env_logger:: try_init ( ) ;
@@ -701,6 +712,7 @@ fn connect_proxy_sends_absolute_uri() {
701
712
rt. block_on ( future:: join ( res, rx) . map ( |r| r. 0 ) ) . unwrap ( ) ;
702
713
}
703
714
715
+ #[ cfg( not( miri) ) ]
704
716
#[ test]
705
717
fn connect_proxy_http_connect_sends_authority_form ( ) {
706
718
let _ = pretty_env_logger:: try_init ( ) ;
@@ -741,6 +753,7 @@ fn connect_proxy_http_connect_sends_authority_form() {
741
753
rt. block_on ( future:: join ( res, rx) . map ( |r| r. 0 ) ) . unwrap ( ) ;
742
754
}
743
755
756
+ #[ cfg( not( miri) ) ]
744
757
#[ test]
745
758
fn client_upgrade ( ) {
746
759
use tokio:: io:: { AsyncReadExt , AsyncWriteExt } ;
@@ -802,6 +815,7 @@ fn client_upgrade() {
802
815
assert_eq ! ( vec, b"bar=foo" ) ;
803
816
}
804
817
818
+ #[ cfg( not( miri) ) ]
805
819
#[ test]
806
820
fn alpn_h2 ( ) {
807
821
use http:: Response ;
0 commit comments