Adds timeouts tonic clients in tests (#8724)

This commit is contained in:
Arya 2024-07-27 11:20:47 -04:00 committed by GitHub
parent 4f6c4aeaa1
commit 14f473d1ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 4 deletions

View File

@ -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"
@ -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");

View File

@ -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) =
@ -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");