From 5ceb9a5fd5750d6c73dd166441f28306039300d0 Mon Sep 17 00:00:00 2001 From: Shailend Chand Date: Fri, 7 Aug 2026 18:54:10 -0700 Subject: [PATCH] Deflake TestMultiContainerEvent/enableCgroupsV2 The test asserted that the exited "quick" container (/bin/true) reports non-zero CPU usage via cgroup v2 cpu.stat. The cgroup2fs charging is correct (exit charges are committed before the parent can reap), but the sentry accounts task CPU time in whole 10ms clock ticks: a task that is never running when the ticker fires accrues zero time. A container as short-lived as /bin/true misses every tick in a few percent of runs, making the assertion flaky. Linux never reports 0 here only because it accounts at nanosecond granularity. Make the quick container burn a short burst of CPU before exiting so that several tick boundaries land while it runs, which makes the accumulated usage reliably non-zero. The v1 and disabled-cgroups subtests are unaffected: the v1 events path keys ContainerUsage by container name rather than ID, and the sentry fallback only counts live thread groups, so both still report 0 for the exited container. PiperOrigin-RevId: 961224935 --- runsc/container/multi_container_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/runsc/container/multi_container_test.go b/runsc/container/multi_container_test.go index 905d724c3e..bd4ecbffb5 100644 --- a/runsc/container/multi_container_test.go +++ b/runsc/container/multi_container_test.go @@ -2382,7 +2382,12 @@ func TestMultiContainerEvent(t *testing.T) { // Setup the containers. sleep := []string{"/bin/sh", "-c", "/bin/sleep 100 | grep 123"} busy := []string{"/bin/bash", "-c", "i=0 ; while true ; do (( i += 1 )) ; done"} - quick := []string{"/bin/true"} + // quick burns a short burst of CPU and exits. The burn must be + // long enough to guarantee that at least one CPU clock tick + // (10ms) lands while its task is running: the sentry accounts + // task CPU time in whole ticks, so a container as short-lived as + // /bin/true can legitimately report zero CPU usage. + quick := []string{"/bin/sh", "-c", "i=0; while [ \"$i\" -lt 50000 ]; do i=$((i+1)); done"} podSpecs, ids := createSpecs(sleep, busy, quick) if name == "enableCgroups" || name == "enableCgroupsV2" { mnt := specs.Mount{