Skip to content

Commit fbcbfe9

Browse files
test(conformance): describe slow-TERM delete and lengthen delay
Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent 93c6fc9 commit fbcbfe9

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

‎tests/suites/conformance/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Each file in `tests/` is one suite.
77
| Suite | Covers |
88
|---|---|
99
| `smoke` | Create a sandbox, run `echo` in it, delete it |
10-
| `lifecycle` | SDK: long-running and run-to-completion sandboxes, running-delete within 10 seconds with a one-second TERM delay, the default command, restart of a stopped sandbox, deleting a stopped sandbox |
10+
| `lifecycle` | SDK: long-running and run-to-completion sandboxes, prompt delete when the workload is slow to handle TERM, the default command, restart of a stopped sandbox, deleting a stopped sandbox |
1111
| `cli` | The same lifecycle through the `openshell` CLI: status, create, get, list, exec, stop, start, delete |
1212
| `persistent-workspace` | Files in `/sandbox` survive stop and start |
1313
| `policy-advisor` | `policy.local` accepts a proposed rule; a denied address or hostname yields one draft rule |

‎tests/suites/conformance/tests/lifecycle.rs‎

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,31 @@ async fn long_running_exec_delete(cx: &mut Context) -> testkit::Result {
4242
cx.expect_absent(&sandbox).await
4343
}
4444

45-
/// Deleting a running workload that delays TERM handling by one second finishes
46-
/// within ten seconds, including disappearance from get and list.
45+
/// Long enough that the workload is still handling TERM when sandbox shutdown
46+
/// begins, and below the supervisor's 5s wait before it kills the workload.
47+
const TERM_HANDLING_DELAY: Duration = Duration::from_secs(3);
48+
49+
/// Well below the 30s termination grace period that a shutdown hang waits out.
50+
const DELETE_DEADLINE: Duration = Duration::from_secs(10);
51+
52+
/// Many workloads do not exit immediately on TERM, for example while they run
53+
/// cleanup handlers. Deleting such a running sandbox should still complete
54+
/// promptly, rather than waiting out the runtime's termination grace period.
4755
#[testkit::test]
48-
async fn running_delete_with_delayed_term_completes_within_ten_seconds(
56+
async fn delete_is_prompt_when_workload_is_slow_to_handle_term(
4957
cx: &mut Context,
5058
) -> testkit::Result {
59+
// `sleep & wait` rather than a foreground `sleep`: sh defers traps until a
60+
// foreground child exits, but `wait` returns on the signal.
61+
let script = format!(
62+
"trap 'sleep {}; exit 0' TERM; \
63+
touch /tmp/delayed-term-ready; \
64+
while :; do sleep 3600 & wait $!; done",
65+
TERM_HANDLING_DELAY.as_secs()
66+
);
5167
let sandbox = cx
5268
.sandbox("dt")
53-
.command([
54-
"sh",
55-
"-c",
56-
"trap 'sleep 1; exit 0' TERM; \
57-
touch /tmp/delayed-term-ready; \
58-
while :; do sleep 3600 & wait $!; done",
59-
])
69+
.command(["sh", "-c", script.as_str()])
6070
.create()
6171
.await?;
6272
sandbox.wait_ready().await?;
@@ -85,14 +95,14 @@ async fn running_delete_with_delayed_term_completes_within_ten_seconds(
8595
// Use one deadline starting before delete, not a fresh timeout per step.
8696
// Boundary containment may kill the workload before its handler finishes;
8797
// this asserts bounded deletion, not a graceful workload exit.
88-
tokio::time::timeout(Duration::from_secs(10), async {
98+
tokio::time::timeout(DELETE_DEADLINE, async {
8999
sandbox.delete().await?;
90100
cx.expect_absent(&sandbox).await
91101
})
92102
.await
93103
.map_err(|_| {
94104
testkit::Error::msg(format!(
95-
"sandbox {} was not fully deleted within 10 seconds",
105+
"sandbox {} was not fully deleted within {DELETE_DEADLINE:?}",
96106
sandbox.name()
97107
))
98108
})?

0 commit comments

Comments
 (0)