|
5 | 5 |
|
6 | 6 | use std::collections::BTreeSet; |
7 | 7 | use std::sync::{Arc, Mutex, PoisonError}; |
8 | | -use std::time::{Duration, Instant}; |
| 8 | +use std::time::Duration; |
9 | 9 |
|
10 | 10 | use openshell_sdk::raw::{AuthedGrpcClient, proto}; |
11 | 11 | use openshell_sdk::{ |
@@ -153,27 +153,29 @@ impl Context { |
153 | 153 |
|
154 | 154 | /// Delete every sandbox the test created and has not deleted. Returns the |
155 | 155 | /// 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. |
156 | 160 | pub(crate) async fn cleanup(&self) -> Vec<String> { |
157 | | - let started = Instant::now(); |
158 | 161 | 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; |
159 | 174 | 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) { |
174 | 176 | match result { |
175 | 177 | Ok(()) => { |
176 | | - lock(&self.sandboxes).remove(&name); |
| 178 | + lock(&self.sandboxes).remove(name); |
177 | 179 | } |
178 | 180 | Err(error) => failures.push(format!("delete sandbox {name}: {error}")), |
179 | 181 | } |
|
0 commit comments