diff options
Diffstat (limited to 'runsc/container/container_test.go')
-rw-r--r-- | runsc/container/container_test.go | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/runsc/container/container_test.go b/runsc/container/container_test.go index a92ae046d..3bbf86534 100644 --- a/runsc/container/container_test.go +++ b/runsc/container/container_test.go @@ -52,7 +52,7 @@ func waitForProcessList(cont *Container, want []*control.Process) error { cb := func() error { got, err := cont.Processes() if err != nil { - err = fmt.Errorf("error getting process data from container: %v", err) + err = fmt.Errorf("error getting process data from container: %w", err) return &backoff.PermanentError{Err: err} } if !procListsEqual(got, want) { @@ -64,11 +64,30 @@ func waitForProcessList(cont *Container, want []*control.Process) error { return testutil.Poll(cb, 30*time.Second) } +// waitForProcess waits for the given process to show up in the container. +func waitForProcess(cont *Container, want *control.Process) error { + cb := func() error { + gots, err := cont.Processes() + if err != nil { + err = fmt.Errorf("error getting process data from container: %w", err) + return &backoff.PermanentError{Err: err} + } + for _, got := range gots { + if procEqual(got, want) { + return nil + } + } + return fmt.Errorf("container got process list: %s, want: %+v", procListToString(gots), want) + } + // Gives plenty of time as tests can run slow under --race. + return testutil.Poll(cb, 30*time.Second) +} + func waitForProcessCount(cont *Container, want int) error { cb := func() error { pss, err := cont.Processes() if err != nil { - err = fmt.Errorf("error getting process data from container: %v", err) + err = fmt.Errorf("error getting process data from container: %w", err) return &backoff.PermanentError{Err: err} } if got := len(pss); got != want { @@ -101,28 +120,32 @@ func procListsEqual(gots, wants []*control.Process) bool { return false } for i := range gots { - got := gots[i] - want := wants[i] - - if want.UID != math.MaxUint32 && want.UID != got.UID { - return false - } - if want.PID != -1 && want.PID != got.PID { - return false - } - if want.PPID != -1 && want.PPID != got.PPID { - return false - } - if len(want.TTY) != 0 && want.TTY != got.TTY { - return false - } - if len(want.Cmd) != 0 && want.Cmd != got.Cmd { + if !procEqual(gots[i], wants[i]) { return false } } return true } +func procEqual(got, want *control.Process) bool { + if want.UID != math.MaxUint32 && want.UID != got.UID { + return false + } + if want.PID != -1 && want.PID != got.PID { + return false + } + if want.PPID != -1 && want.PPID != got.PPID { + return false + } + if len(want.TTY) != 0 && want.TTY != got.TTY { + return false + } + if len(want.Cmd) != 0 && want.Cmd != got.Cmd { + return false + } + return true +} + type processBuilder struct { process control.Process } |