Skip to content

Commit 06f2254

Browse files
ayushr2gvisor-bot
authored andcommitted
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 0968254 ("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 0968254 ("Speed up container_test") PiperOrigin-RevId: 736572600
1 parent 906fb31 commit 06f2254

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

runsc/container/container_test.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -921,24 +921,17 @@ func TestExecProcList(t *testing.T) {
921921
KUID: uid,
922922
}
923923

924-
// Verify that "sleep 100" and "sleep 5" are running after exec. First,
925-
// start running exec (which blocks).
926-
ch := make(chan error)
927-
go func() {
928-
exitStatus, err := cont.executeSync(conf, execArgs)
929-
if err != nil {
930-
ch <- err
931-
} else if exitStatus != 0 {
932-
ch <- fmt.Errorf("failed with exit status: %v", exitStatus)
933-
} else {
934-
ch <- nil
935-
}
936-
}()
924+
// Verify that "sleep 1000" and "sleep 5" are running after exec. First,
925+
// start running exec asynchronously.
926+
pid2, err := cont.Execute(conf, execArgs)
927+
if err != nil {
928+
t.Fatalf("error executing 'sleep 5' command: %v", err)
929+
}
937930

938931
// expectedPL lists the expected process state of the container.
939932
expectedPL := []*control.Process{
940933
newProcessBuilder().PID(1).PPID(0).Cmd("sleep").UID(0).Process(),
941-
newProcessBuilder().PID(2).PPID(0).Cmd("sleep").UID(uid).Process(),
934+
newProcessBuilder().PID(kernel.ThreadID(pid2)).PPID(0).Cmd("sleep").UID(uid).Process(),
942935
}
943936
if err := waitForProcessList(cont, expectedPL); err != nil {
944937
t.Fatalf("error waiting for processes: %v", err)

0 commit comments

Comments
 (0)