Browse Source

Merge #705

705: Tweak heartbeat interval to ensure contract setup always passes r=klochowicz a=klochowicz

See commit msgs for more details.

Fixes #682

Co-authored-by: Mariusz Klochowicz <mariusz@klochowicz.com>
debug-collab-settlement
bors[bot] 3 years ago
committed by GitHub
parent
commit
5f5cdb56f6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .github/workflows/ci.yml
  2. 7
      daemon/src/lib.rs
  3. 9
      daemon/tests/happy_path.rs
  4. 10
      daemon/tests/harness/flow.rs
  5. 23
      daemon/tests/harness/mod.rs

2
.github/workflows/ci.yml

@ -99,6 +99,8 @@ jobs:
- uses: Swatinem/rust-cache@v1.3.0
- run: cargo build --bins --tests
- run: cargo test --workspace
# Ignored tests should be run on the CI
- run: cargo test --workspace -- --ignored
- name: Smoke test ${{ matrix.os }} binary
shell: bash
run: |

7
daemon/src/lib.rs

@ -52,7 +52,12 @@ pub mod wallet;
pub mod wallet_sync;
pub mod wire;
pub const HEARTBEAT_INTERVAL: std::time::Duration = Duration::from_secs(5);
// Certain operations (e.g. contract setup) take long time in debug mode,
// causing us to lag behind in processing heartbeats.
// Increasing the value for debug mode makes sure that we don't cause problems
// when testing / CI, whilst the release can still detect status faster
pub const HEARTBEAT_INTERVAL: std::time::Duration =
Duration::from_secs(if cfg!(debug_assertions) { 30 } else { 5 });
pub const N_PAYOUTS: usize = 200;

9
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,
@ -66,6 +68,7 @@ async fn taker_takes_order_and_maker_rejects() {
}
#[tokio::test]
#[ignore = "expensive, runs on CI"]
async fn taker_takes_order_and_maker_accepts_and_contract_setup() {
let _guard = init_tracing();
let (mut maker, mut taker) = start_both().await;
@ -119,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;

10
daemon/tests/harness/flow.rs

@ -4,6 +4,9 @@ use daemon::tokio_ext::FutureExt;
use std::time::Duration;
use tokio::sync::watch;
/// Waiting time for the time on the watch channel before returning error
const NEXT_WAIT_TIME: Duration = Duration::from_secs(if cfg!(debug_assertions) { 120 } else { 30 });
/// Returns the first `Cfd` from both channels
///
/// Ensures that there is only one `Cfd` present in both channels.
@ -55,9 +58,12 @@ where
T: Clone,
{
rx.changed()
.timeout(Duration::from_secs(10))
.timeout(NEXT_WAIT_TIME)
.await
.context("No change in channel within 10 seconds")??;
.context(format!(
"No change in channel within {} seconds",
NEXT_WAIT_TIME.as_secs()
))??;
Ok(rx.borrow().clone())
}

23
daemon/tests/harness/mod.rs

@ -9,6 +9,7 @@ use daemon::model::{Price, TakerId, Timestamp, Usd};
use daemon::seed::Seed;
use daemon::{
db, maker_cfd, maker_inc_connections, projection, taker_cfd, MakerActorSystem, Tasks,
HEARTBEAT_INTERVAL, N_PAYOUTS,
};
use rust_decimal_macros::dec;
use sqlx::SqlitePool;
@ -30,8 +31,8 @@ pub mod flow;
pub mod maia;
pub mod mocks;
pub const HEARTBEAT_INTERVAL_FOR_TEST: Duration = Duration::from_secs(2);
const N_PAYOUTS_FOR_TEST: usize = 5;
pub const HEARTBEAT_INTERVAL_FOR_TEST: Duration = HEARTBEAT_INTERVAL;
const N_PAYOUTS_FOR_TEST: usize = N_PAYOUTS;
fn oracle_pk() -> schnorrsig::PublicKey {
schnorrsig::PublicKey::from_str(
@ -59,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 {
@ -78,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