Skip to content

Commit

Permalink
feat: improve config stages timeouts; feature-enabling for integratio…
Browse files Browse the repository at this point in the history
…n tests in Cargo.toml
  • Loading branch information
NikitaMasych committed Sep 10, 2024
1 parent 2d36dee commit fd0f116
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ test-mocks = []

[dev-dependencies]
tokio = { version = "^1.39.2", features = ["test-util"] }
futures = "0.3.30"
futures = "0.3.30"

[[test]]
name = "mod"
required-features = ["test-mocks"]
16 changes: 8 additions & 8 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ impl BPConConfig {
party_weights,
threshold,
// TODO: deduce actually good defaults.
launch_timeout: Duration::from_secs(0),
launch1a_timeout: Duration::from_secs(5),
launch1b_timeout: Duration::from_secs(10),
launch2a_timeout: Duration::from_secs(15),
launch2av_timeout: Duration::from_secs(20),
launch2b_timeout: Duration::from_secs(25),
finalize_timeout: Duration::from_secs(30),
grace_period: Duration::from_secs(1),
launch_timeout: Duration::from_millis(0),
launch1a_timeout: Duration::from_millis(200),
launch1b_timeout: Duration::from_millis(400),
launch2a_timeout: Duration::from_millis(600),
launch2av_timeout: Duration::from_millis(800),
launch2b_timeout: Duration::from_millis(1000),
finalize_timeout: Duration::from_millis(1200),
grace_period: Duration::from_millis(0),
}
}
}
25 changes: 19 additions & 6 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ use tokio::time::{sleep, Duration, Instant};

use futures::future::join_all;

/// Returns config with fast timeouts.
fn get_fast_config() -> BPConConfig {
BPConConfig{
launch1a_timeout: Duration::from_millis(0),
launch1b_timeout: Duration::from_millis(50),
launch2a_timeout: Duration::from_millis(100),
launch2av_timeout: Duration::from_millis(150),
launch2b_timeout: Duration::from_millis(200),
finalize_timeout: Duration::from_millis(250),
..Default::default()
}
}

/// Here each party/receiver/sender shall correspond at equal indexes.
type PartiesWithChannels = (
Vec<MockParty>,
Expand Down Expand Up @@ -81,8 +94,8 @@ fn propagate_p2p(
let messages = collect_messages(receivers.as_mut_slice());
broadcast_messages(messages, &senders);

// Delay to simulate network latency and reduce processor load.
sleep(Duration::from_millis(100)).await;
// Reduce processor load.
sleep(Duration::from_millis(1)).await;
}
})
}
Expand Down Expand Up @@ -152,7 +165,7 @@ async fn run_ballot_faulty_party(

#[tokio::test]
async fn test_ballot_happy_case() {
let (parties, receivers, senders) = create_parties(BPConConfig::default());
let (parties, receivers, senders) = create_parties(get_fast_config());
let ballot_tasks = launch_parties(parties);
let p2p_task = propagate_p2p(receivers, senders);
let results = await_results(ballot_tasks).await;
Expand All @@ -163,7 +176,7 @@ async fn test_ballot_happy_case() {

#[tokio::test]
async fn test_ballot_faulty_party_common() {
let parties = create_parties(BPConConfig::default());
let parties = create_parties(get_fast_config());
let elector = DefaultLeaderElector::new();
let leader = elector.elect_leader(&parties.0[0]).unwrap();
let faulty_ids: Vec<usize> = vec![3];
Expand All @@ -180,7 +193,7 @@ async fn test_ballot_faulty_party_common() {

#[tokio::test]
async fn test_ballot_faulty_party_leader() {
let parties = create_parties(BPConConfig::default());
let parties = create_parties(get_fast_config());
let elector = DefaultLeaderElector::new();
let leader = elector.elect_leader(&parties.0[0]).unwrap();
let faulty_ids = vec![leader as usize];
Expand Down Expand Up @@ -223,7 +236,7 @@ async fn test_ballot_malicious_party() {
// actors would be able to DDoS ballot, bloating all the channel with malicious ones.
// For this test to pass, we will send malicious messages once in a while.
let mut last_malicious_message_time = Instant::now();
let malicious_message_interval = Duration::from_secs(3);
let malicious_message_interval = Duration::from_millis(100);
loop {
// Collect all messages first.
let mut messages: Vec<_> = receivers
Expand Down

0 comments on commit fd0f116

Please sign in to comment.