|
1 | 1 | use crate::common::actions::when; |
2 | 2 | use crate::common::assertions::{assert_msg_type, then}; |
3 | 3 | 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}; |
5 | 7 | use std::time::Duration; |
6 | 8 |
|
7 | 9 | /// Tests the automatic heartbeat mechanism in an active FIX session: |
@@ -64,3 +66,25 @@ async fn test_peer_timeout() { |
64 | 66 | when(Duration::from_secs(peer_interval)).elapses().await; |
65 | 67 | then(&mut mock_counterparty).gets_disconnected().await; |
66 | 68 | } |
| 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