use crate::common::actions::when;
use crate::common::assertions::{assert_msg_type, then};
use crate::common::setup::{LOGOUT_TIMEOUT, given_an_active_session};
use hotfix::message::logout::Logout;
use hotfix_message::fix44::MsgType;
use std::time::Duration;
#[tokio::test]
async fn test_happy_logout_initiated_by_us() {
let (session, mut counterparty) = given_an_active_session().await;
when(&session).requests_disconnect().await;
then(&mut counterparty)
.receives(|msg| assert_msg_type(msg, MsgType::Logout))
.await;
when(&mut counterparty)
.sends_message(Logout::default())
.await;
then(&mut counterparty).gets_disconnected().await;
}
#[tokio::test]
async fn test_happy_logout_initiated_by_counterparty() {
let (_session, mut counterparty) = given_an_active_session().await;
when(&mut counterparty)
.sends_message(Logout::default())
.await;
then(&mut counterparty)
.receives(|msg| assert_msg_type(msg, MsgType::Logout))
.await;
then(&mut counterparty).gets_disconnected().await;
}
#[tokio::test(start_paused = true)]
async fn test_logout_timeout_is_handled() {
let (session, mut counterparty) = given_an_active_session().await;
when(&session).requests_disconnect().await;
then(&mut counterparty)
.receives(|msg| assert_msg_type(msg, MsgType::Logout))
.await;
when(Duration::from_secs(LOGOUT_TIMEOUT)).elapses().await;
then(&mut counterparty).gets_disconnected().await;
}