diff options
author | Florian Klink <flokli@flokli.de> | 2023-10-08T11·33+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-10-08T22·50+0000 |
commit | b6bf3a87f162be158fea1386de1ee87a53c4d65b (patch) | |
tree | 30e107ca8dbf80c8fd6321082f65958e0e0fc974 /tvix/castore/src | |
parent | c0376995c9ac4e4b9ca606219035e808fe815d69 (diff) |
test(tvix/castore): use tokio-retry for exp backoff r/6742
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 <flokli@flokli.de> Reviewed-by: Connor Brewster <cbrewster@hey.com> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/castore/src')
-rw-r--r-- | tvix/castore/src/blobservice/grpc.rs | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/tvix/castore/src/blobservice/grpc.rs b/tvix/castore/src/blobservice/grpc.rs index b0544387bb0a..115efa5f09c6 100644 --- a/tvix/castore/src/blobservice/grpc.rs +++ b/tvix/castore/src/blobservice/grpc.rs @@ -281,10 +281,12 @@ impl<W: tokio::io::AsyncWrite + Unpin> 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 = { |