From 8a72d2c0e78cca079f982026379b756a3ab547c6 Mon Sep 17 00:00:00 2001 From: Johanna Larsson Date: Tue, 22 Sep 2026 16:05:32 +0100 Subject: [PATCH] Stop talking to docker in tests that don't need docker `just test` doesn't use docker, but the cleanup was still pruning containers over and over. This switches to only cleaning up containers created by the tests. --- Cargo.lock | 27 +++++++++++++++++++++ crates/tranquil-pds/Cargo.toml | 2 +- crates/tranquil-pds/tests/common/mod.rs | 31 ++++++++++++++++++------- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 33b9f00..eac6cca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1646,6 +1646,21 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "conquer-once" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d008a441c0f269f36ca13712528069a86a3e60dffee1d98b976eb3b0b2160b4" +dependencies = [ + "conquer-util", +] + +[[package]] +name = "conquer-util" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e763eef8846b13b380f37dfecda401770b0ca4e56e95170237bd7c25c7db3582" + [[package]] name = "const-oid" version = "0.9.6" @@ -6560,6 +6575,16 @@ dependencies = [ "thiserror 2.0.18", ] +[[package]] +name = "signal-hook" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d881a16cf4426aa584979d30bd82cb33429027e42122b169753d6ef1085ed6e2" +dependencies = [ + "libc", + "signal-hook-registry", +] + [[package]] name = "signal-hook-registry" version = "1.4.8" @@ -7120,6 +7145,7 @@ dependencies = [ "async-trait", "bollard", "bytes", + "conquer-once", "docker_credential", "either", "etcetera 0.11.0", @@ -7133,6 +7159,7 @@ dependencies = [ "serde", "serde_json", "serde_with", + "signal-hook", "thiserror 2.0.18", "tokio", "tokio-stream", diff --git a/crates/tranquil-pds/Cargo.toml b/crates/tranquil-pds/Cargo.toml index 59fb81a..a082093 100644 --- a/crates/tranquil-pds/Cargo.toml +++ b/crates/tranquil-pds/Cargo.toml @@ -90,7 +90,7 @@ tranquil-infra = { workspace = true, features = ["testing"] } tempfile = "3" ciborium = { workspace = true } ctor = { workspace = true } -testcontainers = { workspace = true } +testcontainers = { workspace = true, features = ["watchdog"] } testcontainers-modules = { workspace = true } tranquil-ripple = { workspace = true } tranquil-sync = { workspace = true } diff --git a/crates/tranquil-pds/tests/common/mod.rs b/crates/tranquil-pds/tests/common/mod.rs index 1ccf602..0aff3af 100644 --- a/crates/tranquil-pds/tests/common/mod.rs +++ b/crates/tranquil-pds/tests/common/mod.rs @@ -83,28 +83,41 @@ fn has_external_infra() -> bool { || (std::env::var("DATABASE_URL").is_ok() && (std::env::var("S3_ENDPOINT").is_ok() || std::env::var("BLOB_STORAGE_PATH").is_ok())) } + +#[cfg(not(feature = "external-infra"))] +fn started_container_ids() -> Vec { + let db = DB_CONTAINER.get().map(|c| c.id().to_string()); + #[cfg(feature = "s3")] + let s3 = S3_CONTAINER.get().map(|c| c.id().to_string()); + #[cfg(not(feature = "s3"))] + let s3: Option = None; + db.into_iter().chain(s3).collect() +} + +#[cfg(feature = "external-infra")] +fn started_container_ids() -> Vec { + Vec::new() +} + #[cfg(test)] #[ctor::dtor] fn cleanup() { if let Some(temp_dir) = TEST_TEMP_DIR.get() { let _ = std::fs::remove_dir_all(temp_dir); } - if has_external_infra() { + let ids = started_container_ids(); + if ids.is_empty() { return; } if std::env::var("XDG_RUNTIME_DIR").is_ok() { let _ = std::process::Command::new("podman") - .args(["rm", "-f", "--filter", "label=tranquil_pds_test=true"]) + .args(["rm", "-f"]) + .args(&ids) .output(); } let _ = std::process::Command::new("docker") - .args([ - "container", - "prune", - "-f", - "--filter", - "label=tranquil_pds_test=true", - ]) + .args(["rm", "-f"]) + .args(&ids) .output(); }