Skip to content

Commit fff4201

Browse files
fix(testkit): give each sandbox its own cleanup timeout
Cleanup shared one two-minute budget across all of a test's sandboxes, so a slow delete left the rest with no time and could leak them on a shared gateway. Delete them concurrently, each with the full timeout. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent d6874e6 commit fff4201

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

‎tests/testkit/testkit/src/context.rs‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use std::collections::BTreeSet;
77
use std::sync::{Arc, Mutex, PoisonError};
8-
use std::time::{Duration, Instant};
8+
use std::time::Duration;
99

1010
use openshell_sdk::raw::{AuthedGrpcClient, proto};
1111
use openshell_sdk::{
@@ -153,27 +153,29 @@ impl Context {
153153

154154
/// Delete every sandbox the test created and has not deleted. Returns the
155155
/// cleanup failures; they are reported separately from the test result.
156+
///
157+
/// Sandboxes are deleted concurrently, each with the full
158+
/// [`CLEANUP_TIMEOUT`], so a slow delete cannot use up the time for the
159+
/// others and cleanup takes about one timeout however many there are.
156160
pub(crate) async fn cleanup(&self) -> Vec<String> {
157-
let started = Instant::now();
158161
let names: Vec<String> = lock(&self.sandboxes).iter().cloned().collect();
162+
let results = futures::future::join_all(names.iter().map(|name| async move {
163+
self.client
164+
.delete_sandbox(
165+
name,
166+
DeleteOptions {
167+
allow_missing: true,
168+
},
169+
)
170+
.await?;
171+
self.client.wait_deleted(name, CLEANUP_TIMEOUT, None).await
172+
}))
173+
.await;
159174
let mut failures = Vec::new();
160-
for name in names {
161-
let remaining = CLEANUP_TIMEOUT.saturating_sub(started.elapsed());
162-
let result = async {
163-
self.client
164-
.delete_sandbox(
165-
&name,
166-
DeleteOptions {
167-
allow_missing: true,
168-
},
169-
)
170-
.await?;
171-
self.client.wait_deleted(&name, remaining, None).await
172-
}
173-
.await;
175+
for (name, result) in names.iter().zip(results) {
174176
match result {
175177
Ok(()) => {
176-
lock(&self.sandboxes).remove(&name);
178+
lock(&self.sandboxes).remove(name);
177179
}
178180
Err(error) => failures.push(format!("delete sandbox {name}: {error}")),
179181
}

0 commit comments

Comments
 (0)