11use crate :: common:: session_actions:: SessionActions ;
2- use crate :: common:: session_assertions:: SessionAssertions ;
3- use crate :: common:: setup:: { HEARTBEAT_INTERVAL , setup} ;
4- use hotfix:: session:: Status ;
2+ use crate :: common:: setup:: { HEARTBEAT_INTERVAL , given_an_active_session} ;
53use hotfix_message:: Part ;
64use hotfix_message:: fix44:: MSG_TYPE ;
75use std:: time:: Duration ;
@@ -17,15 +15,7 @@ use std::time::Duration;
1715/// as required by the FIX protocol to prevent timeout disconnections.
1816#[ tokio:: test( start_paused = true ) ]
1917async fn test_heartbeats ( ) {
20- let ( session, mut mock_counterparty) = setup ( ) . await ;
21-
22- // assert that a logon message is received (type 'A')
23- mock_counterparty
24- . then_receives ( |msg| assert_eq ! ( msg. header( ) . get:: <& str >( MSG_TYPE ) . unwrap( ) , "A" ) )
25- . await ;
26- // counterparty responds with a logon to establish a happy session
27- mock_counterparty. when_logon_is_sent ( ) . await ;
28- session. then_status_changes_to ( Status :: Active ) . await ;
18+ let ( session, mut mock_counterparty) = given_an_active_session ( ) . await ;
2919
3020 // let's wait enough time for a heartbeat and assert that the heartbeat was sent
3121 when_time_elapses ( Duration :: from_secs ( HEARTBEAT_INTERVAL + 1 ) ) . await ;
@@ -48,18 +38,8 @@ async fn test_heartbeats() {
4838/// if no response is received within the timeout period.
4939#[ tokio:: test( start_paused = true ) ]
5040async fn test_peer_timeout ( ) {
51- let ( session, mut mock_counterparty) = setup ( ) . await ;
5241 let peer_interval = ( 1.2 * HEARTBEAT_INTERVAL as f64 ) as u64 + 1 ;
53-
54- // assert that a logon message is received (type 'A')
55- mock_counterparty
56- . then_receives ( |msg| assert_eq ! ( msg. header( ) . get:: <& str >( MSG_TYPE ) . unwrap( ) , "A" ) )
57- . await ;
58- session. then_status_changes_to ( Status :: AwaitingLogon ) . await ;
59-
60- // counterparty responds with a logon to establish a happy session
61- mock_counterparty. when_logon_is_sent ( ) . await ;
62- session. then_status_changes_to ( Status :: Active ) . await ;
42+ let ( _session, mut mock_counterparty) = given_an_active_session ( ) . await ;
6343
6444 // let's wait enough time for a heartbeat and assert that the heartbeat was sent
6545 when_time_elapses ( Duration :: from_secs ( HEARTBEAT_INTERVAL + 1 ) ) . await ;
0 commit comments