Skip to content

Commit

Permalink
fix(test): retry during PUT to fix failures due to node restarts
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin committed Oct 11, 2024
1 parent b532cc4 commit 8af00bb
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions sn_node/tests/data_with_churn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,21 +320,40 @@ fn store_chunks_task(
loop {
let random_data = gen_random_data(*DATA_SIZE);

let data_map = client
.data_put(random_data, &wallet)
.await
.inspect_err(|err| {
println!("Error to put chunk: {err:?}");
error!("Error to put chunk: {err:?}")
})?;

println!("Stored Chunk/s at {data_map:?} after a delay of: {delay:?}");
info!("Stored Chunk/s at {data_map:?} after a delay of: {delay:?}");
// FIXME: The client does not have the retry repay to different payee feature yet.
// Retry here for now
let mut retries = 1;
loop {
match client
.data_put(random_data.clone(), &wallet)
.await
.inspect_err(|err| {
println!("Error to put chunk: {err:?}");
error!("Error to put chunk: {err:?}")
}) {
Ok(data_map) => {
println!("Stored Chunk/s at {data_map:?} after a delay of: {delay:?}");
info!("Stored Chunk/s at {data_map:?} after a delay of: {delay:?}");

content
.write()
.await
.push_back(NetworkAddress::ChunkAddress(ChunkAddress::new(data_map)));
break;
}
Err(err) => {
println!("Failed to store chunk: {err:?}. Retrying ...");
error!("Failed to store chunk: {err:?}. Retrying ...");
if retries >= 3 {
println!("Failed to store chunk after 3 retries: {err}");
error!("Failed to store chunk after 3 retries: {err}");
bail!("Failed to store chunk after 3 retries: {err}");
}
retries += 1;
}
}
}

content
.write()
.await
.push_back(NetworkAddress::ChunkAddress(ChunkAddress::new(data_map)));
sleep(delay).await;
}
});
Expand Down

0 comments on commit 8af00bb

Please sign in to comment.