Skip to content

Commit fd0f116

Browse files
committed
feat: improve config stages timeouts; feature-enabling for integration tests in Cargo.toml
1 parent 2d36dee commit fd0f116

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ test-mocks = []
2828

2929
[dev-dependencies]
3030
tokio = { version = "^1.39.2", features = ["test-util"] }
31-
futures = "0.3.30"
31+
futures = "0.3.30"
32+
33+
[[test]]
34+
name = "mod"
35+
required-features = ["test-mocks"]

src/config.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ impl BPConConfig {
9696
party_weights,
9797
threshold,
9898
// TODO: deduce actually good defaults.
99-
launch_timeout: Duration::from_secs(0),
100-
launch1a_timeout: Duration::from_secs(5),
101-
launch1b_timeout: Duration::from_secs(10),
102-
launch2a_timeout: Duration::from_secs(15),
103-
launch2av_timeout: Duration::from_secs(20),
104-
launch2b_timeout: Duration::from_secs(25),
105-
finalize_timeout: Duration::from_secs(30),
106-
grace_period: Duration::from_secs(1),
99+
launch_timeout: Duration::from_millis(0),
100+
launch1a_timeout: Duration::from_millis(200),
101+
launch1b_timeout: Duration::from_millis(400),
102+
launch2a_timeout: Duration::from_millis(600),
103+
launch2av_timeout: Duration::from_millis(800),
104+
launch2b_timeout: Duration::from_millis(1000),
105+
finalize_timeout: Duration::from_millis(1200),
106+
grace_period: Duration::from_millis(0),
107107
}
108108
}
109109
}

tests/mod.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ use tokio::time::{sleep, Duration, Instant};
1111

1212
use futures::future::join_all;
1313

14+
/// Returns config with fast timeouts.
15+
fn get_fast_config() -> BPConConfig {
16+
BPConConfig{
17+
launch1a_timeout: Duration::from_millis(0),
18+
launch1b_timeout: Duration::from_millis(50),
19+
launch2a_timeout: Duration::from_millis(100),
20+
launch2av_timeout: Duration::from_millis(150),
21+
launch2b_timeout: Duration::from_millis(200),
22+
finalize_timeout: Duration::from_millis(250),
23+
..Default::default()
24+
}
25+
}
26+
1427
/// Here each party/receiver/sender shall correspond at equal indexes.
1528
type PartiesWithChannels = (
1629
Vec<MockParty>,
@@ -81,8 +94,8 @@ fn propagate_p2p(
8194
let messages = collect_messages(receivers.as_mut_slice());
8295
broadcast_messages(messages, &senders);
8396

84-
// Delay to simulate network latency and reduce processor load.
85-
sleep(Duration::from_millis(100)).await;
97+
// Reduce processor load.
98+
sleep(Duration::from_millis(1)).await;
8699
}
87100
})
88101
}
@@ -152,7 +165,7 @@ async fn run_ballot_faulty_party(
152165

153166
#[tokio::test]
154167
async fn test_ballot_happy_case() {
155-
let (parties, receivers, senders) = create_parties(BPConConfig::default());
168+
let (parties, receivers, senders) = create_parties(get_fast_config());
156169
let ballot_tasks = launch_parties(parties);
157170
let p2p_task = propagate_p2p(receivers, senders);
158171
let results = await_results(ballot_tasks).await;
@@ -163,7 +176,7 @@ async fn test_ballot_happy_case() {
163176

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

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

0 commit comments

Comments
 (0)