11use std:: { io, iter, pin:: pin, time:: Duration } ;
22
33use anyhow:: { bail, Result } ;
4- use async_std:: task:: sleep;
54use async_trait:: async_trait;
6- use futures:: prelude:: * ;
5+ use futures:: { future :: pending , prelude:: * } ;
76use libp2p_identity:: PeerId ;
87use libp2p_request_response as request_response;
98use libp2p_request_response:: ProtocolSupport ;
@@ -14,7 +13,7 @@ use request_response::{
1413} ;
1514use tracing_subscriber:: EnvFilter ;
1615
17- #[ async_std :: test]
16+ #[ tokio :: test]
1817async fn report_outbound_failure_on_read_response ( ) {
1918 let _ = tracing_subscriber:: fmt ( )
2019 . with_env_filter ( EnvFilter :: from_default_env ( ) )
@@ -70,7 +69,7 @@ async fn report_outbound_failure_on_read_response() {
7069 futures:: future:: select ( server_task, client_task) . await ;
7170}
7271
73- #[ async_std :: test]
72+ #[ tokio :: test]
7473async fn report_outbound_failure_on_write_request ( ) {
7574 let _ = tracing_subscriber:: fmt ( )
7675 . with_env_filter ( EnvFilter :: from_default_env ( ) )
@@ -113,7 +112,7 @@ async fn report_outbound_failure_on_write_request() {
113112 futures:: future:: select ( server_task, client_task) . await ;
114113}
115114
116- #[ async_std :: test]
115+ #[ tokio :: test]
117116async fn report_outbound_timeout_on_read_response ( ) {
118117 let _ = tracing_subscriber:: fmt ( )
119118 . with_env_filter ( EnvFilter :: from_default_env ( ) )
@@ -160,7 +159,7 @@ async fn report_outbound_timeout_on_read_response() {
160159 futures:: future:: select ( server_task, client_task) . await ;
161160}
162161
163- #[ async_std :: test]
162+ #[ tokio :: test]
164163async fn report_outbound_failure_on_max_streams ( ) {
165164 let _ = tracing_subscriber:: fmt ( )
166165 . with_env_filter ( EnvFilter :: from_default_env ( ) )
@@ -212,7 +211,7 @@ async fn report_outbound_failure_on_max_streams() {
212211 futures:: future:: select ( swarm1_task, swarm2_task) . await ;
213212}
214213
215- #[ async_std :: test]
214+ #[ tokio :: test]
216215async fn report_inbound_failure_on_read_request ( ) {
217216 let _ = tracing_subscriber:: fmt ( )
218217 . with_env_filter ( EnvFilter :: from_default_env ( ) )
@@ -249,7 +248,7 @@ async fn report_inbound_failure_on_read_request() {
249248 futures:: future:: select ( server_task, client_task) . await ;
250249}
251250
252- #[ async_std :: test]
251+ #[ tokio :: test]
253252async fn report_inbound_failure_on_write_response ( ) {
254253 let _ = tracing_subscriber:: fmt ( )
255254 . with_env_filter ( EnvFilter :: from_default_env ( ) )
@@ -315,7 +314,7 @@ async fn report_inbound_failure_on_write_response() {
315314 futures:: future:: select ( server_task, client_task) . await ;
316315}
317316
318- #[ async_std :: test]
317+ #[ tokio :: test]
319318async fn report_inbound_timeout_on_write_response ( ) {
320319 let _ = tracing_subscriber:: fmt ( )
321320 . with_env_filter ( EnvFilter :: from_default_env ( ) )
@@ -465,9 +464,10 @@ impl Codec for TestCodec {
465464
466465 match buf[ 0 ] . try_into ( ) ? {
467466 Action :: FailOnReadResponse => Err ( io:: Error :: other ( "FailOnReadResponse" ) ) ,
468- Action :: TimeoutOnReadResponse => loop {
469- sleep ( Duration :: MAX ) . await ;
470- } ,
467+ Action :: TimeoutOnReadResponse => {
468+ pending :: < ( ) > ( ) . await ;
469+ Err ( io:: Error :: other ( "FailOnReadResponse" ) )
470+ }
471471 action => Ok ( action) ,
472472 }
473473 }
@@ -502,9 +502,10 @@ impl Codec for TestCodec {
502502 {
503503 match res {
504504 Action :: FailOnWriteResponse => Err ( io:: Error :: other ( "FailOnWriteResponse" ) ) ,
505- Action :: TimeoutOnWriteResponse => loop {
506- sleep ( Duration :: MAX ) . await ;
507- } ,
505+ Action :: TimeoutOnWriteResponse => {
506+ pending :: < ( ) > ( ) . await ;
507+ Err ( io:: Error :: other ( "FailOnWriteResponse" ) )
508+ }
508509 action => {
509510 let bytes = [ action. into ( ) ] ;
510511 io. write_all ( & bytes) . await ?;
0 commit comments