1
1
use std:: env;
2
2
use std:: str:: FromStr ;
3
- use std:: time:: Duration ;
3
+ use std:: time:: { Duration , Instant } ;
4
4
5
- use anyhow:: { Context , Result } ;
5
+ use anyhow:: { bail , Context , Result } ;
6
6
use either:: Either ;
7
7
use env_logger:: { Env , Target } ;
8
8
use futures:: { future, AsyncRead , AsyncWrite , StreamExt } ;
@@ -32,11 +32,11 @@ async fn main() -> Result<()> {
32
32
. unwrap_or_else ( |_| "true" . into ( ) )
33
33
. parse :: < bool > ( ) ?;
34
34
35
- let test_timeout = env:: var ( "test_timeout " )
35
+ let test_timeout = env:: var ( "test_timeout_seconds " )
36
36
. unwrap_or_else ( |_| "10" . into ( ) )
37
- . parse :: < usize > ( ) ?;
37
+ . parse :: < u64 > ( ) ?;
38
38
39
- let redis_addr = env:: var ( "REDIS_ADDR " )
39
+ let redis_addr = env:: var ( "redis_addr " )
40
40
. map ( |addr| format ! ( "redis://{addr}" ) )
41
41
. unwrap_or_else ( |_| "redis://redis:6379" . into ( ) ) ;
42
42
@@ -105,26 +105,31 @@ async fn main() -> Result<()> {
105
105
// retrieved via `listenAddr` key over the redis connection. Or wait to be pinged and have
106
106
// `dialerDone` key ready on the redis connection.
107
107
if is_dialer {
108
- let result: Vec < String > = conn. blpop ( "listenerAddr" , test_timeout) . await ?;
108
+ let result: Vec < String > = conn. blpop ( "listenerAddr" , test_timeout as usize ) . await ?;
109
109
let other = result
110
110
. get ( 1 )
111
111
. context ( "Failed to wait for listener to be ready" ) ?;
112
112
113
+ let handshake_start = Instant :: now ( ) ;
114
+
113
115
swarm. dial ( other. parse :: < Multiaddr > ( ) ?) ?;
114
116
log:: info!( "Test instance, dialing multiaddress on: {}." , other) ;
115
117
116
- loop {
118
+ let rtt = loop {
117
119
if let Some ( SwarmEvent :: Behaviour ( BehaviourEvent :: Ping ( ping:: Event {
118
120
peer : _,
119
121
result : Ok ( ping:: Success :: Ping { rtt } ) ,
120
122
} ) ) ) = swarm. next ( ) . await
121
123
{
122
124
log:: info!( "Ping successful: {rtt:?}" ) ;
123
- break ;
125
+ break rtt . as_millis ( ) as f32 ;
124
126
}
125
- }
127
+ } ;
126
128
127
- conn. rpush ( "dialerDone" , "" ) . await ?;
129
+ let handshake_plus_ping = handshake_start. elapsed ( ) . as_millis ( ) as f32 ;
130
+ println ! (
131
+ r#"{{"handshakePlusOneRTTMillis": {handshake_plus_ping:.1}, "pingRTTMilllis": {rtt:.1}}}"#
132
+ ) ;
128
133
} else {
129
134
loop {
130
135
if let Some ( SwarmEvent :: NewListenAddr {
@@ -149,11 +154,8 @@ async fn main() -> Result<()> {
149
154
swarm. next ( ) . await ;
150
155
}
151
156
} ) ;
152
-
153
- let done: Vec < String > = conn. blpop ( "dialerDone" , test_timeout) . await ?;
154
- done. get ( 1 )
155
- . context ( "Failed to wait for dialer conclusion" ) ?;
156
- log:: info!( "Ping successful" ) ;
157
+ tokio:: time:: sleep ( Duration :: from_secs ( test_timeout) ) . await ;
158
+ bail ! ( "Test should have been killed by the test runner!" ) ;
157
159
}
158
160
159
161
Ok ( ( ) )
0 commit comments