Deflake TestExecProcList.

There is a race in the test where the goroutine running Container.executeSync()
calls WaitPID() => IsSandboxRunning() which accesses Container.Sandbox.

This can race with the defer Container.Destroy which sets Sandbox = nil.

This race was introduced in 0968254ce7 ("Speed up container_test") which got
rid of the read on channel `ch`.

Fix the race by exec-ing asynchronously. This maintains the old behavior of not
checking if the exit status of sleep.

Fixes 0968254ce7 ("Speed up container_test")

PiperOrigin-RevId: 736572600
This commit is contained in:
Ayush Ranjan
2025-03-13 11:18:16 -07:00
committed by gVisor bot
parent 906fb319cc
commit 06f2254962
+7 -14
View File
@@ -921,24 +921,17 @@ func TestExecProcList(t *testing.T) {
KUID: uid,
}
// Verify that "sleep 100" and "sleep 5" are running after exec. First,
// start running exec (which blocks).
ch := make(chan error)
go func() {
exitStatus, err := cont.executeSync(conf, execArgs)
if err != nil {
ch <- err
} else if exitStatus != 0 {
ch <- fmt.Errorf("failed with exit status: %v", exitStatus)
} else {
ch <- nil
}
}()
// Verify that "sleep 1000" and "sleep 5" are running after exec. First,
// start running exec asynchronously.
pid2, err := cont.Execute(conf, execArgs)
if err != nil {
t.Fatalf("error executing 'sleep 5' command: %v", err)
}
// expectedPL lists the expected process state of the container.
expectedPL := []*control.Process{
newProcessBuilder().PID(1).PPID(0).Cmd("sleep").UID(0).Process(),
newProcessBuilder().PID(2).PPID(0).Cmd("sleep").UID(uid).Process(),
newProcessBuilder().PID(kernel.ThreadID(pid2)).PPID(0).Cmd("sleep").UID(uid).Process(),
}
if err := waitForProcessList(cont, expectedPL); err != nil {
t.Fatalf("error waiting for processes: %v", err)