Skip to content

Commit 6522ccd

Browse files
committed
Add test case for sending heartbeats in response to test requests
1 parent 2707992 commit 6522ccd

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

crates/hotfix/tests/session_test_cases/heartbeat_tests.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use crate::common::actions::when;
22
use crate::common::assertions::{assert_msg_type, then};
33
use crate::common::setup::{HEARTBEAT_INTERVAL, given_an_active_session};
4-
use hotfix_message::fix44::MsgType;
4+
use hotfix::message::test_request::TestRequest;
5+
use hotfix_message::Part;
6+
use hotfix_message::fix44::{MsgType, TEST_REQ_ID};
57
use std::time::Duration;
68

79
/// Tests the automatic heartbeat mechanism in an active FIX session:
@@ -64,3 +66,25 @@ async fn test_peer_timeout() {
6466
when(Duration::from_secs(peer_interval)).elapses().await;
6567
then(&mut mock_counterparty).gets_disconnected().await;
6668
}
69+
70+
/// Tests that we send a heartbeat in response to Test Requests.
71+
///
72+
/// The `TestReqID` of the heartbeat (field 112) should match that of the request.
73+
#[tokio::test(start_paused = true)]
74+
async fn test_heartbeat_in_response_to_test_request() {
75+
let (session, mut mock_counterparty) = given_an_active_session().await;
76+
77+
let test_request = TestRequest::new("abc-123".to_string());
78+
when(&mut mock_counterparty)
79+
.sends_message(test_request)
80+
.await;
81+
then(&mut mock_counterparty)
82+
.receives(|msg| {
83+
assert_msg_type(msg, MsgType::Heartbeat);
84+
assert_eq!(msg.get::<&str>(TEST_REQ_ID).unwrap(), "abc-123");
85+
})
86+
.await;
87+
88+
when(&session).requests_disconnect().await;
89+
then(&mut mock_counterparty).gets_disconnected().await;
90+
}

0 commit comments

Comments
 (0)