diff options
author | Andrei Vagin <avagin@google.com> | 2019-01-11 10:31:21 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-01-11 10:32:26 -0800 |
commit | f8c8f241540fa79b47090ce4808c2c0cfbe44a12 (patch) | |
tree | 493726adeeb4f6c38619ec49c42cbd72d0578097 /runsc/container/container_test.go | |
parent | bde588ff05cad3591025a1e313eebe61cd82e421 (diff) |
runsc: Collect zombies of sandbox and gofer processes
And we need to wait a gofer process before cgroup.Uninstall,
because it is running in the sandbox cgroups.
PiperOrigin-RevId: 228904020
Change-Id: Iaf8826d5b9626db32d4057a1c505a8d7daaeb8f9
Diffstat (limited to 'runsc/container/container_test.go')
-rw-r--r-- | runsc/container/container_test.go | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/runsc/container/container_test.go b/runsc/container/container_test.go index 45a36e583..affb51fab 100644 --- a/runsc/container/container_test.go +++ b/runsc/container/container_test.go @@ -39,9 +39,6 @@ import ( "gvisor.googlesource.com/gvisor/runsc/test/testutil" ) -// childReaper reaps child processes. -var childReaper *testutil.Reaper - // waitForProcessList waits for the given process list to show up in the container. func waitForProcessList(cont *Container, want []*control.Process) error { cb := func() error { @@ -75,6 +72,18 @@ func waitForProcessCount(cont *Container, want int) error { return testutil.Poll(cb, 30*time.Second) } +func blockUntilWaitable(pid int) error { + _, _, err := testutil.RetryEintr(func() (uintptr, uintptr, error) { + var err error + _, _, err1 := syscall.Syscall6(syscall.SYS_WAITID, 1, uintptr(pid), 0, syscall.WEXITED|syscall.WNOWAIT, 0, 0) + if err1 != 0 { + err = err1 + } + return 0, 0, err + }) + return err +} + // procListsEqual is used to check whether 2 Process lists are equal for all // implemented fields. func procListsEqual(got, want []*control.Process) bool { @@ -256,6 +265,11 @@ func configs(opts ...configOption) []*boot.Config { // It verifies after each step that the container can be loaded from disk, and // has the correct status. func TestLifecycle(t *testing.T) { + // Start the child reaper. + childReaper := &testutil.Reaper{} + childReaper.Start() + defer childReaper.Stop() + for _, conf := range configs(all...) { t.Logf("Running test with conf: %+v", conf) // The container will just sleep for a long time. We will kill it before @@ -1505,10 +1519,7 @@ func TestGoferExits(t *testing.T) { t.Fatalf("error killing sandbox process: %v", err) } - _, _, err = testutil.RetryEintr(func() (uintptr, uintptr, error) { - cpid, err := syscall.Wait4(c.GoferPid, nil, 0, nil) - return uintptr(cpid), 0, err - }) + err = blockUntilWaitable(c.GoferPid) if err != nil && err != syscall.ECHILD { t.Errorf("error waiting for gofer to exit: %v", err) } @@ -1576,10 +1587,6 @@ func TestUserLog(t *testing.T) { } func TestWaitOnExitedSandbox(t *testing.T) { - // Disable the childReaper for this test. - childReaper.Stop() - defer childReaper.Start() - for _, conf := range configs(all...) { t.Logf("Running test with conf: %+v", conf) @@ -1712,10 +1719,5 @@ func TestMain(m *testing.M) { } testutil.RunAsRoot() - // Start the child reaper. - childReaper = &testutil.Reaper{} - childReaper.Start() - defer childReaper.Stop() - os.Exit(m.Run()) } |