Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Add retries to grpc progress message test #823

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions tests/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,8 @@ async fn grpc_server_functional_test() {

let swap_id = retry_until_swap_id(&mut farcaster_client_2).await;

tokio::time::sleep(time::Duration::from_secs(5)).await;

// Test progress
let request = tonic::Request::new(ProgressRequest {
id: 10,
swap_id: swap_id.clone(),
});
let response = farcaster_client_2.progress(request).await;
assert_eq!(response.unwrap().into_inner().id, 10);

tokio::time::sleep(time::Duration::from_secs(5)).await;
retry_until_progress(&mut farcaster_client_2, swap_id.clone()).await;

// Test needs funding
let (address, amount) = retry_until_bitcoin_funding_info(&mut farcaster_client_1).await;
Expand Down Expand Up @@ -258,7 +249,7 @@ async fn retry_until_bitcoin_funding_info(
blockchain: farcaster::Blockchain::Bitcoin.into(),
});
let response = client.needs_funding(request).await;
let NeedsFundingResponse { id, funding_infos } = response.unwrap().into_inner();
let NeedsFundingResponse { funding_infos, .. } = response.unwrap().into_inner();
if !funding_infos.is_empty() {
return (
bitcoin::Address::from_str(&funding_infos[0].address).unwrap(),
Expand All @@ -269,3 +260,21 @@ async fn retry_until_bitcoin_funding_info(
}
panic!("timeout before funding info could be retrieved")
}

async fn retry_until_progress(
client: &mut FarcasterClient<tonic::transport::Channel>,
swap_id: String,
) {
for _ in 0..ALLOWED_RETRIES {
let request = tonic::Request::new(ProgressRequest {
id: 10,
swap_id: swap_id.clone(),
});
let response = client.progress(request).await;
if let Ok(response) = response {
assert_eq!(response.into_inner().id, 10);
return;
}
tokio::time::sleep(time::Duration::from_secs(1)).await;
}
}