Skip to content

Commit bc3ab21

Browse files
committed
test(e2e): poll until the leftover agent Job count settles
The self-cleanup assertion counted Jobs once and required exactly 1. Kubernetes deletion is asynchronous, so a Job whose delete the concurrent runs already issued and acked stays listable while its pods terminate and its finalizers clear -- the assertion then failed with "found 2" for a cleanup that worked correctly. Poll until the count settles, failing only after AGENT_JOB_SETTLE_TIMEOUT (60s, overridable). Only the timing becomes tolerant; the final assertion is still exactly 1. Signed-off-by: Alex Yuskauskas <ayuskauskas@nvidia.com>
1 parent 70c4491 commit bc3ab21

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

tests/e2e/run.sh

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ CREATED_FAKE_GPU_OPERATOR_DEPLOYMENT=false
5656
CREATED_FAKE_CLUSTER_POLICY=false
5757
CREATED_FAKE_CLUSTER_POLICY_CRD=false
5858

59+
# Seconds to wait for the concurrent runs' self-deleted Jobs to disappear from
60+
# the API before the self-cleanup assertion gives up. Deletion is asynchronous,
61+
# so the count settles shortly after the CLI returns rather than at that instant.
62+
AGENT_JOB_SETTLE_TIMEOUT="${AGENT_JOB_SETTLE_TIMEOUT:-60}"
63+
5964
# Run IDs of the snapshot-agent runs this script launched, space separated.
6065
# cleanup_e2e deletes only these Jobs. Every agent run carries the same
6166
# app.kubernetes.io/{name,component} labels, so a label-only sweep would also
@@ -700,15 +705,30 @@ snapshot_run_isolation_body() {
700705
fi
701706
pass "snapshot/isolation/retained-run-survives"
702707

703-
# Each concurrent run must have removed its own resources.
704-
local leftover_jobs
708+
# Each concurrent run must have removed its own resources: exactly the
709+
# retained Job survives.
710+
#
711+
# Poll rather than sample once. Kubernetes deletion is asynchronous -- a Job
712+
# whose delete the CLI already issued and acked stays listable while its
713+
# pods terminate and its finalizers clear, so a single read can legitimately
714+
# still see it and report "found 2" for a cleanup that worked. Only the
715+
# timing is tolerant; the assertion below is still exact.
716+
local leftover_jobs=""
705717
local agent_job_selector="app.kubernetes.io/name=aicr,app.kubernetes.io/component=snapshot-agent"
706-
leftover_jobs=$(kubectl get jobs -n "$ns" -l "$agent_job_selector" -o name 2>/dev/null | wc -l | tr -d ' ')
707-
if [ "$leftover_jobs" != "1" ]; then
708-
kubectl get jobs -n "$ns" -l "$agent_job_selector" -o name || true
709-
fail "snapshot/isolation/self-cleanup" "expected only the retained Job to remain, found ${leftover_jobs}"
710-
return 1
711-
fi
718+
local deadline=$((SECONDS + AGENT_JOB_SETTLE_TIMEOUT))
719+
while :; do
720+
leftover_jobs=$(kubectl get jobs -n "$ns" -l "$agent_job_selector" -o name 2>/dev/null | wc -l | tr -d ' ')
721+
if [ "$leftover_jobs" = "1" ]; then
722+
break
723+
fi
724+
if [ "$SECONDS" -ge "$deadline" ]; then
725+
kubectl get jobs -n "$ns" -l "$agent_job_selector" -o name || true
726+
fail "snapshot/isolation/self-cleanup" \
727+
"expected only the retained Job to remain after ${AGENT_JOB_SETTLE_TIMEOUT}s, found ${leftover_jobs}"
728+
return 1
729+
fi
730+
sleep 2
731+
done
712732
pass "snapshot/isolation/self-cleanup"
713733

714734
# The decoy must have survived every run above.

0 commit comments

Comments
 (0)