about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-10-08T11·40+0200
committerclbot <clbot@tvl.fyi>2023-10-08T22·50+0000
commita464088d2e3cc9bb0ff7a432d592157a811ef6c8 (patch)
tree6bc98f4e4f8b2eeb7a1631096d985984bc0d1d95
parentb6bf3a87f162be158fea1386de1ee87a53c4d65b (diff)
test(tvix/store): use tokio-retry for exp backoff r/6743
Rather than using this loop, use exponential backoff while waiting for
the socket path to be created.

Change-Id: I3056b1525784cd712b1d81f84876c9ca0be10dc6
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9569
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: Connor Brewster <cbrewster@hey.com>
Tested-by: BuildkiteCI
-rw-r--r--tvix/Cargo.lock1
-rw-r--r--tvix/Cargo.nix4
-rw-r--r--tvix/store/Cargo.toml1
-rw-r--r--tvix/store/src/pathinfoservice/grpc.rs32
4 files changed, 21 insertions, 17 deletions
diff --git a/tvix/Cargo.lock b/tvix/Cargo.lock
index 5a9c290a7a39..e5e4870c3de7 100644
--- a/tvix/Cargo.lock
+++ b/tvix/Cargo.lock
@@ -2818,6 +2818,7 @@ dependencies = [
  "thiserror",
  "tokio",
  "tokio-listener",
+ "tokio-retry",
  "tokio-stream",
  "tokio-util",
  "tonic",
diff --git a/tvix/Cargo.nix b/tvix/Cargo.nix
index 68ec9b545279..868620b76ad2 100644
--- a/tvix/Cargo.nix
+++ b/tvix/Cargo.nix
@@ -8634,6 +8634,10 @@ rec {
             name = "test-case";
             packageId = "test-case";
           }
+          {
+            name = "tokio-retry";
+            packageId = "tokio-retry";
+          }
         ];
         features = {
           "default" = [ "fuse" "tonic-reflection" ];
diff --git a/tvix/store/Cargo.toml b/tvix/store/Cargo.toml
index e4ebfc9a0f0f..43421ef4a302 100644
--- a/tvix/store/Cargo.toml
+++ b/tvix/store/Cargo.toml
@@ -77,6 +77,7 @@ tonic-build = "0.10.2"
 [dev-dependencies]
 test-case = "2.2.2"
 tempfile = "3.3.0"
+tokio-retry = "0.3.0"
 
 [features]
 default = ["fuse", "tonic-reflection"]
diff --git a/tvix/store/src/pathinfoservice/grpc.rs b/tvix/store/src/pathinfoservice/grpc.rs
index a8cd1c0c2d80..a88828083940 100644
--- a/tvix/store/src/pathinfoservice/grpc.rs
+++ b/tvix/store/src/pathinfoservice/grpc.rs
@@ -180,10 +180,12 @@ impl PathInfoService for GRPCPathInfoService {
 #[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::pathinfoservice::MemoryPathInfoService;
@@ -274,13 +276,11 @@ mod tests {
         let tmpdir = TempDir::new().unwrap();
         let socket_path = tmpdir.path().join("daemon");
 
-        // let mut join_set = JoinSet::new();
-
-        let path_copy = socket_path.clone();
+        let path_clone = socket_path.clone();
 
         // Spin up a server
         tokio::spawn(async {
-            let uds = UnixListener::bind(path_copy).unwrap();
+            let uds = UnixListener::bind(path_clone).unwrap();
             let uds_stream = UnixListenerStream::new(uds);
 
             // spin up a new server
@@ -298,21 +298,19 @@ mod tests {
         });
 
         // wait for the socket to be created
-        {
-            let mut socket_created = false;
-            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;
-            }
+            },
+        )
+        .await
+        .expect("failed to wait for socket");
 
-            assert!(
-                socket_created,
-                "expected socket path to eventually get created, but never happened"
-            );
-        }
         // prepare a client
         let grpc_client = {
             let url = url::Url::parse(&format!("grpc+unix://{}", socket_path.display()))