Skip to content

Commit

Permalink
Adds timeouts tonic clients in tests (#8724)
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 authored Jul 27, 2024
1 parent 4f6c4ae commit 14f473d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 8 additions & 2 deletions zebra-grpc/src/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ async fn start_server_and_get_client() -> (
MockService<ScanRequest, ScanResponse, PanicAssertion>,
) {
// get a mocked scan service
let mock_scan_service = MockService::build().for_unit_tests();
let mock_scan_service = MockService::build()
.with_max_request_delay(Duration::from_secs(2))
.for_unit_tests();

// start the gRPC server
let listen_addr: std::net::SocketAddr = "127.0.0.1:0"
Expand All @@ -246,8 +248,12 @@ async fn start_server_and_get_client() -> (
// wait for the server to start
sleep(Duration::from_secs(1));

let endpoint = tonic::transport::channel::Endpoint::new(format!("http://{listen_addr}"))
.unwrap()
.timeout(Duration::from_secs(2));

// connect to the gRPC server
let client = ScannerClient::connect(format!("http://{listen_addr}"))
let client = ScannerClient::connect(endpoint)
.await
.expect("server should receive connection");

Expand Down
11 changes: 9 additions & 2 deletions zebra-rpc/src/indexer/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ async fn start_server_and_get_client() -> Result<(
.parse()
.expect("hard-coded IP and u16 port should parse successfully");

let mock_read_service = MockService::build().for_unit_tests();
let mock_read_service = MockService::build()
.with_max_request_delay(Duration::from_secs(2))
.for_unit_tests();

let (mock_chain_tip_change, mock_chain_tip_change_sender) = MockChainTip::new();

let (server_task, listen_addr) =
Expand All @@ -67,8 +70,12 @@ async fn start_server_and_get_client() -> Result<(
// wait for the server to start
tokio::time::sleep(Duration::from_secs(1)).await;

let endpoint = tonic::transport::channel::Endpoint::new(format!("http://{listen_addr}"))
.unwrap()
.timeout(Duration::from_secs(2));

// connect to the gRPC server
let client = IndexerClient::connect(format!("http://{listen_addr}"))
let client = IndexerClient::connect(endpoint)
.await
.expect("server should receive connection");

Expand Down

0 comments on commit 14f473d

Please sign in to comment.