Skip to content

Commit

Permalink
Merge pull request #797 from TheCharlatan/stableGrpcTest
Browse files Browse the repository at this point in the history
Tests: Use retries until swap id is available in grpc test
  • Loading branch information
Lederstrumpf authored Dec 2, 2022
2 parents 9a8183f + 1fdc3f5 commit 9238401
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions tests/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub mod farcaster {
tonic::include_proto!("farcaster");
}

const ALLOWED_RETRIES: u32 = 100;

#[tokio::test]
#[ignore]
async fn grpc_server_functional_test() {
Expand Down Expand Up @@ -133,12 +135,7 @@ async fn grpc_server_functional_test() {
let response = farcaster_client_2.take(request).await;
assert_eq!(response.unwrap().into_inner().id, 5);

// Wait for and retrieve swap id
tokio::time::sleep(time::Duration::from_secs(15)).await;

let request = tonic::Request::new(InfoRequest { id: 6 });
let InfoResponse { swaps, .. } = farcaster_client_2.info(request).await.unwrap().into_inner();
let swap_id = swaps[0].clone();
let swap_id = retry_until_swap_id(&mut farcaster_client_2).await;

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

Expand Down Expand Up @@ -211,11 +208,9 @@ async fn grpc_server_functional_test() {
let request = tonic::Request::new(take_request.clone());
let response = farcaster_client_2.take(request).await;
assert_eq!(response.unwrap().into_inner().id, 5);
// Wait for and retrieve swap id
tokio::time::sleep(time::Duration::from_secs(5)).await;
let request = tonic::Request::new(InfoRequest { id: 6 });
let InfoResponse { swaps, .. } = farcaster_client_2.info(request).await.unwrap().into_inner();
let swap_id = swaps[0].clone();

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

// wait for funding
tokio::time::sleep(time::Duration::from_secs(10)).await;
let request = tonic::Request::new(NeedsFundingRequest {
Expand Down Expand Up @@ -256,3 +251,15 @@ async fn grpc_server_functional_test() {

kill_all();
}

async fn retry_until_swap_id(client: &mut FarcasterClient<tonic::transport::Channel>) -> String {
for _ in 0..ALLOWED_RETRIES {
let request = tonic::Request::new(InfoRequest { id: 6 });
let InfoResponse { swaps, .. } = client.info(request).await.unwrap().into_inner();
if !swaps.is_empty() {
return swaps[0].clone();
}
tokio::time::sleep(time::Duration::from_secs(1)).await;
}
panic!("timeout before a swap id could be retrieved")
}

0 comments on commit 9238401

Please sign in to comment.