diff --git a/Cargo.toml b/Cargo.toml index 6a3655d..527aacf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,4 +28,8 @@ test-mocks = [] [dev-dependencies] tokio = { version = "^1.39.2", features = ["test-util"] } -futures = "0.3.30" \ No newline at end of file +futures = "0.3.30" + +[[test]] +name = "mod" +required-features = ["test-mocks"] \ No newline at end of file diff --git a/src/config.rs b/src/config.rs index 9926e29..a234f22 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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), } } } diff --git a/tests/mod.rs b/tests/mod.rs index 4c2d2e8..a29cada 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -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, @@ -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; } }) } @@ -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; @@ -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 = vec![3]; @@ -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]; @@ -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