File tree Expand file tree Collapse file tree 2 files changed +38
-4
lines changed
tests/integration/blockchain/transports Expand file tree Collapse file tree 2 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -330,7 +330,24 @@ async fn test_websocket_connection_timeout() {
330330 let invalid_url = "ws://invalid-domain-that-does-not-exist:12345" ;
331331
332332 let network = create_test_network_with_urls ( vec ! [ invalid_url] ) ;
333+
334+ // Measure time to ensure it fails quickly due to timeout
335+ let start = std:: time:: Instant :: now ( ) ;
333336 let result = MidnightWsTransportClient :: new ( & network, Some ( config) ) . await ;
334- assert ! ( result. is_err( ) ) ;
335- assert ! ( result. unwrap_err( ) . to_string( ) . contains( "timeout" ) ) ;
337+ let elapsed = start. elapsed ( ) ;
338+
339+ assert ! ( result. is_err( ) , "Should fail with invalid URL" ) ;
340+ // Verify it failed quickly (within 100ms) which indicates the timeout worked
341+ assert ! (
342+ elapsed < Duration :: from_millis( 10 ) ,
343+ "Should fail quickly due to timeout, took {:?}" ,
344+ elapsed
345+ ) ;
346+ // The error should indicate connection failure
347+ let error_msg = result. unwrap_err ( ) . to_string ( ) ;
348+ assert ! (
349+ error_msg. contains( "Failed to connect" ) ,
350+ "Error should indicate connection failure, got: {}" ,
351+ error_msg
352+ ) ;
336353}
Original file line number Diff line number Diff line change @@ -363,7 +363,24 @@ async fn test_websocket_connection_timeout() {
363363 let invalid_url = "ws://invalid-domain-that-does-not-exist:12345" ;
364364
365365 let network = create_test_network_with_urls ( vec ! [ invalid_url] ) ;
366+
367+ // Measure time to ensure it fails quickly due to timeout
368+ let start = std:: time:: Instant :: now ( ) ;
366369 let result = WsTransportClient :: new ( & network, Some ( config) ) . await ;
367- assert ! ( result. is_err( ) ) ;
368- assert ! ( result. unwrap_err( ) . to_string( ) . contains( "timeout" ) ) ;
370+ let elapsed = start. elapsed ( ) ;
371+
372+ assert ! ( result. is_err( ) , "Should fail with invalid URL" ) ;
373+ // Verify it failed quickly (within 100ms) which indicates the timeout worked
374+ assert ! (
375+ elapsed < Duration :: from_millis( 10 ) ,
376+ "Should fail quickly due to timeout, took {:?}" ,
377+ elapsed
378+ ) ;
379+ // The error should indicate connection failure
380+ let error_msg = result. unwrap_err ( ) . to_string ( ) ;
381+ assert ! (
382+ error_msg. contains( "Failed to connect" ) ,
383+ "Error should indicate connection failure, got: {}" ,
384+ error_msg
385+ ) ;
369386}
You can’t perform that action at this time.
0 commit comments