@@ -15,6 +15,7 @@ use futures_util::stream::StreamExt;
15
15
use futures_util:: { self , Stream } ;
16
16
use http_body_util:: BodyExt ;
17
17
use http_body_util:: { Empty , Full , StreamBody } ;
18
+ use tokio:: io:: { AsyncReadExt , AsyncWriteExt } ;
18
19
19
20
use hyper:: body:: Bytes ;
20
21
use hyper:: body:: Frame ;
@@ -89,33 +90,30 @@ fn drop_body_before_eof_closes_connection() {
89
90
async fn drop_client_closes_idle_connections ( ) {
90
91
let _ = pretty_env_logger:: try_init ( ) ;
91
92
92
- let server = TcpListener :: bind ( "127.0.0.1:0" ) . unwrap ( ) ;
93
+ let server = tokio :: net :: TcpListener :: bind ( "127.0.0.1:0" ) . await . unwrap ( ) ;
93
94
let addr = server. local_addr ( ) . unwrap ( ) ;
94
95
let ( closes_tx, mut closes) = mpsc:: channel ( 10 ) ;
95
96
96
97
let ( tx1, rx1) = oneshot:: channel ( ) ;
97
- let ( _client_drop_tx, client_drop_rx) = oneshot:: channel :: < ( ) > ( ) ;
98
98
99
- thread:: spawn ( move || {
100
- let mut sock = server. accept ( ) . unwrap ( ) . 0 ;
101
- sock. set_read_timeout ( Some ( Duration :: from_secs ( 5 ) ) ) . unwrap ( ) ;
102
- sock. set_write_timeout ( Some ( Duration :: from_secs ( 5 ) ) )
103
- . unwrap ( ) ;
99
+ let t1 = tokio:: spawn ( async move {
100
+ let mut sock = server. accept ( ) . await . unwrap ( ) . 0 ;
104
101
let mut buf = [ 0 ; 4096 ] ;
105
- sock. read ( & mut buf) . expect ( "read 1" ) ;
102
+ sock. read ( & mut buf) . await . expect ( "read 1" ) ;
106
103
let body = [ b'x' ; 64 ] ;
107
- write ! (
108
- sock,
109
- "HTTP/1.1 200 OK\r \n Content-Length: {}\r \n \r \n " ,
110
- body. len( )
111
- )
112
- . expect ( "write head" ) ;
113
- let _ = sock. write_all ( & body) ;
104
+ let headers = format ! ( "HTTP/1.1 200 OK\r \n Content-Length: {}\r \n \r \n " , body. len( ) ) ;
105
+ sock. write_all ( headers. as_bytes ( ) )
106
+ . await
107
+ . expect ( "write head" ) ;
108
+ sock. write_all ( & body) . await . expect ( "write body" ) ;
114
109
let _ = tx1. send ( ( ) ) ;
115
110
116
111
// prevent this thread from closing until end of test, so the connection
117
112
// stays open and idle until Client is dropped
118
- runtime ( ) . block_on ( client_drop_rx. into_future ( ) )
113
+ match sock. read ( & mut buf) . await {
114
+ Ok ( n) => assert_eq ! ( n, 0 ) ,
115
+ Err ( _) => ( ) ,
116
+ }
119
117
} ) ;
120
118
121
119
let client = Client :: builder ( TokioExecutor :: new ( ) ) . build ( DebugConnector :: with_http_and_closes (
@@ -149,6 +147,7 @@ async fn drop_client_closes_idle_connections() {
149
147
futures_util:: pin_mut!( t) ;
150
148
let close = closes. into_future ( ) . map ( |( opt, _) | opt. expect ( "closes" ) ) ;
151
149
future:: select ( t, close) . await ;
150
+ t1. await . unwrap ( ) ;
152
151
}
153
152
154
153
#[ cfg( not( miri) ) ]
0 commit comments