1+ use crate :: common:: session_actions:: SessionActions ;
12use crate :: common:: session_assertions:: SessionAssertions ;
23use crate :: common:: setup:: { HEARTBEAT_INTERVAL , setup} ;
34use hotfix:: session:: Status ;
45use hotfix_message:: Part ;
56use hotfix_message:: fix44:: MSG_TYPE ;
67use std:: time:: Duration ;
78
8- async fn when_time_advances ( duration : Duration ) {
9- tokio:: time:: advance ( duration) . await ;
10- }
11-
129/// Tests the automatic heartbeat mechanism in an active FIX session:
1310/// 1. Establishes a session by exchanging logon messages with the counterparty
1411/// 2. Advances time beyond the configured heartbeat interval
@@ -31,13 +28,13 @@ async fn test_heartbeats() {
3128 session. then_status_changes_to ( Status :: Active ) . await ;
3229
3330 // let's wait enough time for a heartbeat and assert that the heartbeat was sent
34- when_time_advances ( Duration :: from_secs ( HEARTBEAT_INTERVAL + 1 ) ) . await ;
31+ when_time_elapses ( Duration :: from_secs ( HEARTBEAT_INTERVAL + 1 ) ) . await ;
3532 mock_counterparty
3633 . then_receives ( |msg| assert_eq ! ( msg. header( ) . get:: <& str >( MSG_TYPE ) . unwrap( ) , "0" ) )
3734 . await ;
3835
39- session. when_disconnected ( ) . await ;
40- mock_counterparty. then_disconnects ( ) . await ;
36+ session. when_disconnect_is_requested ( ) . await ;
37+ mock_counterparty. then_gets_disconnected ( ) . await ;
4138}
4239
4340/// Tests the peer timeout and disconnection mechanism:
@@ -65,19 +62,23 @@ async fn test_peer_timeout() {
6562 session. then_status_changes_to ( Status :: Active ) . await ;
6663
6764 // let's wait enough time for a heartbeat and assert that the heartbeat was sent
68- when_time_advances ( Duration :: from_secs ( HEARTBEAT_INTERVAL + 1 ) ) . await ;
65+ when_time_elapses ( Duration :: from_secs ( HEARTBEAT_INTERVAL + 1 ) ) . await ;
6966 mock_counterparty
7067 . then_receives ( |msg| assert_eq ! ( msg. header( ) . get:: <& str >( MSG_TYPE ) . unwrap( ) , "0" ) )
7168 . await ;
7269
7370 // we wait enough time for the peer deadline to pass
74- when_time_advances ( Duration :: from_secs ( peer_interval - HEARTBEAT_INTERVAL ) ) . await ;
71+ when_time_elapses ( Duration :: from_secs ( peer_interval - HEARTBEAT_INTERVAL ) ) . await ;
7572 // a TestRequest (type '1') is sent to the counterparty
7673 mock_counterparty
7774 . then_receives ( |msg| assert_eq ! ( msg. header( ) . get:: <& str >( MSG_TYPE ) . unwrap( ) , "1" ) )
7875 . await ;
7976
8077 // we wait even longer and the counterparty never responds, so we disconnect from the counterparty
81- when_time_advances ( Duration :: from_secs ( peer_interval) ) . await ;
82- mock_counterparty. then_disconnects ( ) . await ;
78+ when_time_elapses ( Duration :: from_secs ( peer_interval) ) . await ;
79+ mock_counterparty. then_gets_disconnected ( ) . await ;
80+ }
81+
82+ async fn when_time_elapses ( duration : Duration ) {
83+ tokio:: time:: advance ( duration) . await ;
8384}
0 commit comments