Skip to content

Commit e9cf02c

Browse files
committed
Test container deletion when runc create process is killed by SIGKILL.
Signed-off-by: HirazawaUi <[email protected]>
1 parent 1247c1a commit e9cf02c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/integration/delete.bats

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,48 @@ EOF
276276
# Expect "no such unit" exit code.
277277
run -4 systemctl status $user "$SD_UNIT_NAME"
278278
}
279+
280+
@test "runc delete after create process killed" {
281+
# This test verifies that a container can be properly deleted
282+
# even if the runc create process was killed with SIGKILL
283+
284+
# This test is restricted to cgroupv1 due to runc create's short execution window.
285+
# Empirical data shows cgroupv1 configuration latency exceeds cgroupv2, making it
286+
# more suitable for timing-sensitive operations. Despite this selectivity,
287+
# the test remains inherently flaky. Remove if
288+
# flakiness exceeds acceptable thresholds.
289+
requires root cgroups_v1
290+
set_cgroups_path
291+
292+
# Add many device rules to further slow down cgroup creation
293+
update_config '.linux.resources.devices = []'
294+
for i in {1..300}; do
295+
update_config '.linux.resources.devices += [{"allow": true, "access": "rwm", "type": "c", "major": '"$i"', "minor": 0}]'
296+
done
297+
298+
# Start runc create and kill it after 5ms with SIGKILL
299+
timeout --signal=SIGKILL --kill-after=0 0.05s "$RUNC" --debug ${RUNC_USE_SYSTEMD+--systemd-cgroup} --root "$ROOT/state" create --console-socket "$CONSOLE_SOCKET" test_create_killed || true
300+
301+
# Wait briefly to ensure background processes complete
302+
sleep 1
303+
304+
# Check container state - should be in stopped or paused state after SIGKILL
305+
runc state test_create_killed
306+
[ "$status" -eq 0 ]
307+
[[ "$output" == *"stopped"* || "$output" == *"paused"* ]]
308+
309+
runc delete --force test_create_killed
310+
[ "$status" -eq 0 ]
311+
312+
# Verify container no longer exists in the list
313+
runc list
314+
[[ "$output" != *"test_create_killed"* ]]
315+
316+
# Check for any leftover runc init processes
317+
remaining_inits=$(pgrep -f "runc.*init.*test_create_killed" || true)
318+
[ -z "$remaining_inits" ] || fail "leftover runc init processes: $remaining_inits"
319+
320+
# Check for leftover cgroups using standard pattern
321+
output=$(find /sys/fs/cgroup -path "$REL_CGROUPS_PATH" 2>/dev/null || true)
322+
[ -z "$output" ] || fail "leftover cgroups found: $output"
323+
}

0 commit comments

Comments
 (0)