From b6bf3a87f162be158fea1386de1ee87a53c4d65b Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 8 Oct 2023 13:33:43 +0200 Subject: test(tvix/castore): use tokio-retry for exp backoff Rather than using this loop, use exponential backoff while waiting for the socket path to be created. Change-Id: I18706a64ce06f8916a07892dfbcd409ac5b3bff1 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9568 Autosubmit: flokli Reviewed-by: Connor Brewster Tested-by: BuildkiteCI --- tvix/castore/Cargo.toml | 3 ++- tvix/castore/src/blobservice/grpc.rs | 28 +++++++++++++--------------- 2 files changed, 15 insertions(+), 16 deletions(-) (limited to 'tvix/castore') diff --git a/tvix/castore/Cargo.toml b/tvix/castore/Cargo.toml index 8f96c3fbf6..4dab3bfa44 100644 --- a/tvix/castore/Cargo.toml +++ b/tvix/castore/Cargo.toml @@ -34,7 +34,8 @@ tonic-build = "0.10.2" [dev-dependencies] test-case = "2.2.2" tempfile = "3.3.0" +tokio-retry = "0.3.0" [features] default = [] -tonic-reflection = ["dep:tonic-reflection"] \ No newline at end of file +tonic-reflection = ["dep:tonic-reflection"] diff --git a/tvix/castore/src/blobservice/grpc.rs b/tvix/castore/src/blobservice/grpc.rs index b0544387bb..115efa5f09 100644 --- a/tvix/castore/src/blobservice/grpc.rs +++ b/tvix/castore/src/blobservice/grpc.rs @@ -281,10 +281,12 @@ impl tokio::io::AsyncWrite for GRPCBlobWriter< #[cfg(test)] mod tests { use std::sync::Arc; + use std::time::Duration; use tempfile::TempDir; use tokio::net::UnixListener; - use tokio::time; + use tokio_retry::strategy::ExponentialBackoff; + use tokio_retry::Retry; use tokio_stream::wrappers::UnixListenerStream; use crate::blobservice::MemoryBlobService; @@ -374,22 +376,18 @@ mod tests { }); // wait for the socket to be created - { - let mut socket_created = false; - // TODO: exponential backoff urgently - for _try in 1..20 { + Retry::spawn( + ExponentialBackoff::from_millis(20).max_delay(Duration::from_secs(10)), + || async { if socket_path.exists() { - socket_created = true; - break; + Ok(()) + } else { + Err(()) } - tokio::time::sleep(time::Duration::from_millis(20)).await; - } - - assert!( - socket_created, - "expected socket path to eventually get created, but never happened" - ); - } + }, + ) + .await + .expect("failed to wait for socket"); // prepare a client let grpc_client = { -- cgit 1.4.1