test(tvix/store): 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: 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
This commit is contained in:
Florian Klink 2023-10-08 13:40:20 +02:00 committed by clbot
parent b6bf3a87f1
commit a464088d2e
4 changed files with 21 additions and 17 deletions

1
tvix/Cargo.lock generated
View file

@ -2818,6 +2818,7 @@ dependencies = [
"thiserror",
"tokio",
"tokio-listener",
"tokio-retry",
"tokio-stream",
"tokio-util",
"tonic",

View file

@ -8634,6 +8634,10 @@ rec {
name = "test-case";
packageId = "test-case";
}
{
name = "tokio-retry";
packageId = "tokio-retry";
}
];
features = {
"default" = [ "fuse" "tonic-reflection" ];

View file

@ -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"]

View file

@ -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()))