Skip to content

Commit

Permalink
Add test: multi-raft (n=1)
Browse files Browse the repository at this point in the history
  • Loading branch information
akiradeveloper committed May 24, 2024
1 parent 0a7bf91 commit d0543a1
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions tests/lol-tests/tests/multi_raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,41 @@ async fn N3_L100_K3_multi_raft_cluster() -> Result<()> {
Ok(())
}

const L: u32 = 20;
const REP: u32 = 300;

#[serial]
#[tokio::test(flavor = "multi_thread")]
async fn N1_L100_K3_multi_raft_io() -> Result<()> {
const L: u32 = 100;
let cluster = Arc::new(Cluster::new(1, L).await?);

let mut futs = vec![];
for lane_id in 0..L {
let cluster = cluster.clone();
let fut = async move {
cluster.add_server(lane_id, 0, 0).await?;
Ok::<(), anyhow::Error>(())
};
futs.push(fut);
}
futures::future::try_join_all(futs).await?;

let mut cur_state = [0; L as usize];
for _ in 0..300 {
let lane_id = rand::thread_rng().gen_range(0..L);
let add_v = rand::thread_rng().gen_range(1..=9);
let old_v = cluster.user(0).fetch_add(lane_id, add_v).await?;
assert_eq!(old_v, cur_state[lane_id as usize]);
cur_state[lane_id as usize] += add_v;
}

Ok(())
}

#[serial]
#[tokio::test(flavor = "multi_thread")]
async fn N3_L20_K3_multi_raft_io() -> Result<()> {
const L: u32 = 20;

let cluster = Arc::new(Cluster::new(3, L).await?);

let mut futs = vec![];
Expand All @@ -63,8 +92,8 @@ async fn N3_L20_K3_multi_raft_io() -> Result<()> {
}
futures::future::try_join_all(futs).await?;

let mut cur_state = [0; 1000];
for _ in 0..REP {
let mut cur_state = [0; L as usize];
for _ in 0..300 {
let lane_id = rand::thread_rng().gen_range(0..L);
let add_v = rand::thread_rng().gen_range(1..=9);
let leader = (lane_id % 3) as u8;
Expand Down

0 comments on commit d0543a1

Please sign in to comment.