Skip to content

Commit

Permalink
hopefully fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkeldenker committed May 9, 2024
1 parent b4f61eb commit a8ca540
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions crates/core/src/ampc/dht/mod.rs
Expand Up @@ -184,7 +184,7 @@ pub mod tests {
#[traced_test]
async fn test_simple_set_get() -> anyhow::Result<()> {
let (raft1, server1, addr1) = server(1).await?;
let (raft2, server2, addr2) = server(2).await?;
let (_, server2, addr2) = server(2).await?;

let servers = vec![server1, server2];

Expand All @@ -211,16 +211,6 @@ pub mod tests {
}
};

if let Err(e) = raft2.initialize(members.clone()).await {
match e {
openraft::error::RaftError::APIError(e) => match e {
InitializeError::NotAllowed(_) => {}
InitializeError::NotInMembers(_) => panic!("{:?}", e),
},
openraft::error::RaftError::Fatal(_) => panic!("{:?}", e),
}
};

let c1 = RemoteClient::new(addr1);
let c2 = RemoteClient::new(addr2);

Expand All @@ -236,6 +226,13 @@ pub mod tests {
let res = c1.get(table.clone(), "hello".as_bytes().into()).await?;
assert_eq!(res, Some("world".as_bytes().into()));

c2.set(
table.clone(),
"ensure-linearized-read".as_bytes().into(),
vec![].into(),
)
.await?;

let res = c2.get(table.clone(), "hello".as_bytes().into()).await?;
assert_eq!(res, Some("world".as_bytes().into()));

Expand All @@ -246,6 +243,13 @@ pub mod tests {
)
.await?;

c1.set(
table.clone(),
"ensure-linearized-read".as_bytes().into(),
vec![].into(),
)
.await?;

let res = c1.get(table.clone(), "hello".as_bytes().into()).await?;
assert_eq!(res, Some("world2".as_bytes().into()));

Expand Down Expand Up @@ -299,7 +303,13 @@ pub mod tests {
"world".as_bytes().into(),
)
.await?;
tokio::time::sleep(std::time::Duration::from_secs(1)).await; // reads are not linearized (only eventual consistency)

c2.set(
table.clone(),
"ensure-linearized-read".as_bytes().into(),
vec![].into(),
)
.await?;

let res = c2.get(table.clone(), "hello".as_bytes().into()).await?;

Expand Down

0 comments on commit a8ca540

Please sign in to comment.