about summary refs log tree commit diff
path: root/tvix/store/src/pathinfoservice/grpc.rs
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 /tvix/store/src/pathinfoservice/grpc.rs
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
Diffstat (limited to 'tvix/store/src/pathinfoservice/grpc.rs')
-rw-r--r--tvix/store/src/pathinfoservice/grpc.rs32
1 files changed, 15 insertions, 17 deletions
diff --git a/tvix/store/src/pathinfoservice/grpc.rs b/tvix/store/src/pathinfoservice/grpc.rs
index a8cd1c0c2d..a888280839 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()))