1
1
use std:: { io, iter, pin:: pin, time:: Duration } ;
2
2
3
3
use anyhow:: { bail, Result } ;
4
- use async_std:: task:: sleep;
5
4
use async_trait:: async_trait;
6
- use futures:: prelude:: * ;
5
+ use futures:: { future :: pending , prelude:: * } ;
7
6
use libp2p_identity:: PeerId ;
8
7
use libp2p_request_response as request_response;
9
8
use libp2p_request_response:: ProtocolSupport ;
@@ -14,7 +13,7 @@ use request_response::{
14
13
} ;
15
14
use tracing_subscriber:: EnvFilter ;
16
15
17
- #[ async_std :: test]
16
+ #[ tokio :: test]
18
17
async fn report_outbound_failure_on_read_response ( ) {
19
18
let _ = tracing_subscriber:: fmt ( )
20
19
. with_env_filter ( EnvFilter :: from_default_env ( ) )
@@ -70,7 +69,7 @@ async fn report_outbound_failure_on_read_response() {
70
69
futures:: future:: select ( server_task, client_task) . await ;
71
70
}
72
71
73
- #[ async_std :: test]
72
+ #[ tokio :: test]
74
73
async fn report_outbound_failure_on_write_request ( ) {
75
74
let _ = tracing_subscriber:: fmt ( )
76
75
. with_env_filter ( EnvFilter :: from_default_env ( ) )
@@ -113,7 +112,7 @@ async fn report_outbound_failure_on_write_request() {
113
112
futures:: future:: select ( server_task, client_task) . await ;
114
113
}
115
114
116
- #[ async_std :: test]
115
+ #[ tokio :: test]
117
116
async fn report_outbound_timeout_on_read_response ( ) {
118
117
let _ = tracing_subscriber:: fmt ( )
119
118
. with_env_filter ( EnvFilter :: from_default_env ( ) )
@@ -160,7 +159,7 @@ async fn report_outbound_timeout_on_read_response() {
160
159
futures:: future:: select ( server_task, client_task) . await ;
161
160
}
162
161
163
- #[ async_std :: test]
162
+ #[ tokio :: test]
164
163
async fn report_outbound_failure_on_max_streams ( ) {
165
164
let _ = tracing_subscriber:: fmt ( )
166
165
. with_env_filter ( EnvFilter :: from_default_env ( ) )
@@ -212,7 +211,7 @@ async fn report_outbound_failure_on_max_streams() {
212
211
futures:: future:: select ( swarm1_task, swarm2_task) . await ;
213
212
}
214
213
215
- #[ async_std :: test]
214
+ #[ tokio :: test]
216
215
async fn report_inbound_failure_on_read_request ( ) {
217
216
let _ = tracing_subscriber:: fmt ( )
218
217
. with_env_filter ( EnvFilter :: from_default_env ( ) )
@@ -249,7 +248,7 @@ async fn report_inbound_failure_on_read_request() {
249
248
futures:: future:: select ( server_task, client_task) . await ;
250
249
}
251
250
252
- #[ async_std :: test]
251
+ #[ tokio :: test]
253
252
async fn report_inbound_failure_on_write_response ( ) {
254
253
let _ = tracing_subscriber:: fmt ( )
255
254
. with_env_filter ( EnvFilter :: from_default_env ( ) )
@@ -315,7 +314,7 @@ async fn report_inbound_failure_on_write_response() {
315
314
futures:: future:: select ( server_task, client_task) . await ;
316
315
}
317
316
318
- #[ async_std :: test]
317
+ #[ tokio :: test]
319
318
async fn report_inbound_timeout_on_write_response ( ) {
320
319
let _ = tracing_subscriber:: fmt ( )
321
320
. with_env_filter ( EnvFilter :: from_default_env ( ) )
@@ -465,9 +464,10 @@ impl Codec for TestCodec {
465
464
466
465
match buf[ 0 ] . try_into ( ) ? {
467
466
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
+ }
471
471
action => Ok ( action) ,
472
472
}
473
473
}
@@ -502,9 +502,10 @@ impl Codec for TestCodec {
502
502
{
503
503
match res {
504
504
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
+ }
508
509
action => {
509
510
let bytes = [ action. into ( ) ] ;
510
511
io. write_all ( & bytes) . await ?;
0 commit comments