Browse Source

Use shorter heartbeat timeout in test that waits for it

By default tests use the same heartbeat interval as production code.
Allow adjusting the value using builder pattern is tests that otherwise take too
long to complete (as they wait for timeout to trigger).
debug-collab-settlement
Mariusz Klochowicz 3 years ago
parent
commit
e43325d888
No known key found for this signature in database GPG Key ID: 470C865699C8D4D
  1. 8
      daemon/tests/happy_path.rs
  2. 18
      daemon/tests/harness/mod.rs

8
daemon/tests/happy_path.rs

@ -1,3 +1,5 @@
use std::time::Duration;
use crate::harness::flow::{is_next_none, next, next_cfd, next_order, next_some};
use crate::harness::{
assert_is_same_order, dummy_new_order, init_tracing, start_both, Maker, MakerConfig, Taker,
@ -120,17 +122,19 @@ async fn taker_takes_order_and_maker_accepts_and_contract_setup() {
#[tokio::test]
async fn taker_notices_lack_of_maker() {
let short_interval = Duration::from_secs(1);
let _guard = init_tracing();
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let local_addr = listener.local_addr().unwrap();
let maker_config = MakerConfig::default();
let maker_config = MakerConfig::default().with_heartbeat_interval(short_interval);
let maker = Maker::start(&maker_config, listener).await;
let taker_config = TakerConfig::default();
let taker_config = TakerConfig::default().with_heartbeat_timeout(short_interval * 2);
let mut taker = Taker::start(&taker_config, maker.listen_addr, maker.identity_pk).await;

18
daemon/tests/harness/mod.rs

@ -60,6 +60,15 @@ pub struct MakerConfig {
n_payouts: usize,
}
impl MakerConfig {
pub fn with_heartbeat_interval(self, interval: Duration) -> Self {
Self {
heartbeat_interval: interval,
..self
}
}
}
impl Default for MakerConfig {
fn default() -> Self {
Self {
@ -79,6 +88,15 @@ pub struct TakerConfig {
n_payouts: usize,
}
impl TakerConfig {
pub fn with_heartbeat_timeout(self, timeout: Duration) -> Self {
Self {
heartbeat_timeout: timeout,
..self
}
}
}
impl Default for TakerConfig {
fn default() -> Self {
Self {

Loading…
Cancel
Save