mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
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 in0968254ce7("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. Fixes0968254ce7("Speed up container_test") PiperOrigin-RevId: 736572600
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user