summaryrefslogtreecommitdiffhomepage
path: root/runsc/container
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2018-09-28 18:14:59 -0700
committerShentubot <shentubot@google.com>2018-09-28 18:16:10 -0700
commit50c283b9f56bb7200938d9e207355f05f79f0d17 (patch)
treeeb059dd1911c7acc70350b01cfce6c17e5de7aab /runsc/container
parentcfdd418fe23880cad88639596c1171cbe7ad6ffb (diff)
Add test for 'signall --all' with stopped container
PiperOrigin-RevId: 215025517 Change-Id: I04b9d8022b3d9dfe279e466ddb91310b9860b9af
Diffstat (limited to 'runsc/container')
-rw-r--r--runsc/container/multi_container_test.go120
1 files changed, 76 insertions, 44 deletions
diff --git a/runsc/container/multi_container_test.go b/runsc/container/multi_container_test.go
index 3d7385a82..e5f7daf60 100644
--- a/runsc/container/multi_container_test.go
+++ b/runsc/container/multi_container_test.go
@@ -527,54 +527,86 @@ func TestMultiContainerProcesses(t *testing.T) {
// TestMultiContainerKillAll checks that all process that belong to a container
// are killed when SIGKILL is sent to *all* processes in that container.
func TestMultiContainerKillAll(t *testing.T) {
- app, err := testutil.FindFile("runsc/container/test_app")
- if err != nil {
- t.Fatal("error finding test_app:", err)
- }
+ for _, tc := range []struct {
+ killContainer bool
+ }{
+ {killContainer: true},
+ {killContainer: false},
+ } {
+ app, err := testutil.FindFile("runsc/container/test_app")
+ if err != nil {
+ t.Fatal("error finding test_app:", err)
+ }
- // First container will remain intact while the second container is killed.
- specs, ids := createSpecs(
- []string{app, "task-tree", "--depth=2", "--width=2"},
- []string{app, "task-tree", "--depth=4", "--width=2"})
- conf := testutil.TestConfig()
- containers, cleanup, err := startContainers(conf, specs, ids)
- if err != nil {
- t.Fatalf("error starting containers: %v", err)
- }
- defer cleanup()
+ // First container will remain intact while the second container is killed.
+ specs, ids := createSpecs(
+ []string{app, "task-tree", "--depth=2", "--width=2"},
+ []string{app, "task-tree", "--depth=4", "--width=2"})
+ conf := testutil.TestConfig()
+ containers, cleanup, err := startContainers(conf, specs, ids)
+ if err != nil {
+ t.Fatalf("error starting containers: %v", err)
+ }
+ defer cleanup()
- // Wait until all processes are created.
- rootProcCount := int(math.Pow(2, 3) - 1)
- if err := waitForProcessCount(containers[0], rootProcCount); err != nil {
- t.Fatal(err)
- }
- procCount := int(math.Pow(2, 5) - 1)
- if err := waitForProcessCount(containers[1], procCount); err != nil {
- t.Fatal(err)
- }
+ // Wait until all processes are created.
+ rootProcCount := int(math.Pow(2, 3) - 1)
+ if err := waitForProcessCount(containers[0], rootProcCount); err != nil {
+ t.Fatal(err)
+ }
+ procCount := int(math.Pow(2, 5) - 1)
+ if err := waitForProcessCount(containers[1], procCount); err != nil {
+ t.Fatal(err)
+ }
- // Exec more processes to ensure signal works for exec'd processes too.
- args := &control.ExecArgs{
- Filename: app,
- Argv: []string{app, "task-tree", "--depth=2", "--width=2"},
- }
- if _, err := containers[1].Execute(args); err != nil {
- t.Fatalf("error exec'ing: %v", err)
- }
- procCount += 3
- if err := waitForProcessCount(containers[1], procCount); err != nil {
- t.Fatal(err)
- }
+ // Exec more processes to ensure signal works for exec'd processes too.
+ args := &control.ExecArgs{
+ Filename: app,
+ Argv: []string{app, "task-tree", "--depth=2", "--width=2"},
+ }
+ if _, err := containers[1].Execute(args); err != nil {
+ t.Fatalf("error exec'ing: %v", err)
+ }
+ procCount += 3
+ if err := waitForProcessCount(containers[1], procCount); err != nil {
+ t.Fatal(err)
+ }
+
+ if tc.killContainer {
+ // First kill the init process to make the container be stopped with
+ // processes still running inside.
+ containers[1].Signal(syscall.SIGKILL, false)
+ op := func() error {
+ c, err := Load(conf.RootDir, ids[1])
+ if err != nil {
+ return err
+ }
+ if c.Status != Stopped {
+ return fmt.Errorf("container is not stopped")
+ }
+ return nil
+ }
+ if err := testutil.Poll(op, 5*time.Second); err != nil {
+ t.Fatalf("container did not stop %q: %v", containers[1].ID, err)
+ }
+ }
- // Kill'Em All
- containers[1].Signal(syscall.SIGKILL, true)
+ c, err := Load(conf.RootDir, ids[1])
+ if err != nil {
+ t.Fatalf("failed to load child container %q: %v", c.ID, err)
+ }
+ // Kill'Em All
+ if err := c.Signal(syscall.SIGKILL, true); err != nil {
+ t.Fatalf("failed to send SIGKILL to container %q: %v", c.ID, err)
+ }
- // Check that all processes are gone.
- if err := waitForProcessCount(containers[1], 0); err != nil {
- t.Fatal(err)
- }
- // Check that root container was not affected.
- if err := waitForProcessCount(containers[0], rootProcCount); err != nil {
- t.Fatal(err)
+ // Check that all processes are gone.
+ if err := waitForProcessCount(containers[1], 0); err != nil {
+ t.Fatal(err)
+ }
+ // Check that root container was not affected.
+ if err := waitForProcessCount(containers[0], rootProcCount); err != nil {
+ t.Fatal(err)
+ }
}
}