-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d595d2f
commit 6eac056
Showing
9 changed files
with
151 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use anyhow::Result; | ||
use std::time::Duration; | ||
|
||
#[tokio::test(flavor = "multi_thread")] | ||
async fn create() -> Result<()> { | ||
let mut env = env::Env::new(true, true); | ||
env.add_node(0, 1); | ||
env.check_connectivity(0).await?; | ||
Ok(()) | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread")] | ||
async fn create_remove() -> Result<()> { | ||
let mut env = env::Env::new(true, true); | ||
env.add_node(0, 1); | ||
env.check_connectivity(0).await?; | ||
let addr0 = env.address(0); | ||
env.remove_node(0); | ||
tokio::time::sleep(Duration::from_secs(1)).await; | ||
|
||
env.add_node(0, 1); | ||
env.check_connectivity(0).await?; | ||
let addr1 = env.address(0); | ||
|
||
assert_eq!(addr0, addr1); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use anyhow::Result; | ||
use rand::Rng; | ||
use sorock_tests::*; | ||
use std::time::Duration; | ||
|
||
#[tokio::test(flavor = "multi_thread")] | ||
async fn n3_restore() -> Result<()> { | ||
let mut cluster = Cluster::builder() | ||
.with_persistency(true) | ||
.build(3, 1) | ||
.await?; | ||
cluster.add_server(0, 0, 0).await?; | ||
cluster.add_server(0, 0, 1).await?; | ||
cluster.add_server(0, 1, 2).await?; | ||
|
||
let mut cur_state = 0; | ||
for _ in 0..10 { | ||
let add_v = rand::thread_rng().gen_range(1..=9); | ||
let old_v = cluster.user(0).fetch_add(0, add_v).await?; | ||
assert_eq!(old_v, cur_state); | ||
cur_state += add_v; | ||
} | ||
|
||
cluster.env().remove_node(0); | ||
cluster.env().remove_node(1); | ||
cluster.env().remove_node(2); | ||
tokio::time::sleep(Duration::from_secs(1)).await; | ||
|
||
cluster.env().add_node(0, 1); | ||
cluster.env().add_node(1, 1); | ||
// Wait for election. | ||
tokio::time::sleep(Duration::from_secs(5)).await; | ||
assert_eq!(cluster.user(1).read(0).await?, cur_state); | ||
|
||
Ok(()) | ||
} |