Skip to content

Commit

Permalink
Merge pull request #384 from drmingdrmer/2-client-request
Browse files Browse the repository at this point in the history
Fixup: client_request() should return a result instead of panic
  • Loading branch information
drmingdrmer committed Jun 21, 2022
2 parents 7d9ed45 + 8b0db8e commit d69a20b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion openraft/tests/benchmark/bench_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async fn do_bench(bench_config: &BenchConfig) -> anyhow::Result<()> {
let now = Instant::now();

for i in 0..n {
router.client_request(0, "foo", i as u64).await
router.client_request(0, "foo", i as u64).await?;
}

let elapsed = now.elapsed();
Expand Down
18 changes: 14 additions & 4 deletions openraft/tests/fixtures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,12 @@ where
}

/// Send a client request to the target node, causing test failure on error.
pub async fn client_request(&self, mut target: C::NodeId, client_id: &str, serial: u64) {
pub async fn client_request(
&self,
mut target: C::NodeId,
client_id: &str,
serial: u64,
) -> Result<(), ClientWriteError<C::NodeId>> {
for ith in 0..3 {
let req = <C::D as IntoMemClientRequest<C::D>>::make_request(client_id, serial);
if let Err(err) = self.send_client_request(target, req).await {
Expand All @@ -560,11 +565,16 @@ where
}
_ => {}
}
panic!("{:?}", err)
return Err(err);
} else {
return;
return Ok(());
}
}

unreachable!(
"Max retry times exceeded. Can not finish client_request, target={}, client_id={} serial={}",
target, client_id, serial
)
}

/// Send external request to the particular node.
Expand Down Expand Up @@ -596,7 +606,7 @@ where
count: usize,
) -> Result<(), ClientWriteError<C::NodeId>> {
for idx in 0..count {
self.client_request(target, client_id, idx as u64).await
self.client_request(target, client_id, idx as u64).await?;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion openraft/tests/membership/t00_learner_restart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn learner_restart() -> Result<()> {
}

router.add_learner(0, 1).await?;
router.client_request(0, "foo", 1).await;
router.client_request(0, "foo", 1).await?;
log_index += 2;

router.wait_for_log(&btreeset![0, 1], Some(log_index), None, "write one log").await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async fn metrics_state_machine_consistency() -> Result<()> {
log_index += 1;

tracing::info!("--- write one log");
router.client_request(0, "foo", 1).await;
router.client_request(0, "foo", 1).await?;

// Wait for metrics to be up to date.
// Once last_applied updated, the key should be visible in state machine.
Expand Down
2 changes: 1 addition & 1 deletion openraft/tests/state_machine/t40_clean_applied_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn clean_applied_logs() -> Result<()> {

let count = (10 - log_index) as usize;
for idx in 0..count {
router.client_request(0, "0", idx as u64).await;
router.client_request(0, "0", idx as u64).await?;
// raft commit at once with a single leader cluster.
// If we send too fast, logs are removed before forwarding to learner.
// Then it triggers snapshot replication, which is not expected.
Expand Down

0 comments on commit d69a20b

Please sign in to comment.