From c4b048df5e098222428e4e71de9532617e7c2d1e Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Wed, 2 Mar 2016 11:05:08 -0800 Subject: [PATCH] Added a test for making sure executor destroy works --- client/driver/executor/executor_test.go | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/client/driver/executor/executor_test.go b/client/driver/executor/executor_test.go index 6499720b7..072a9336c 100644 --- a/client/driver/executor/executor_test.go +++ b/client/driver/executor/executor_test.go @@ -149,6 +149,50 @@ func TestExecutor_IsolationAndConstraints(t *testing.T) { } } +func TestExecutor_DestroyCgroup(t *testing.T) { + testutil.ExecCompatible(t) + + execCmd := ExecCommand{Cmd: "/bin/bash", Args: []string{"-c", "/usr/bin/yes"}} + ctx := testExecutorContext(t) + ctx.LogConfig.MaxFiles = 1 + ctx.LogConfig.MaxFileSizeMB = 300 + //defer ctx.AllocDir.Destroy() + + ctx.FSIsolation = true + ctx.ResourceLimits = true + ctx.UnprivilegedUser = true + + executor := NewExecutor(log.New(os.Stdout, "", log.LstdFlags)) + ps, err := executor.LaunchCmd(&execCmd, ctx) + if err != nil { + t.Fatalf("error in launching command: %v", err) + } + if ps.Pid == 0 { + t.Fatalf("expected process to start and have non zero pid") + } + go func() { + _, err = executor.Wait() + if err != nil { + t.Fatalf("error in waiting for command: %v", err) + } + }() + time.Sleep(200 * time.Millisecond) + executor.Exit() + file := filepath.Join(ctx.AllocDir.LogDir(), "web.stdout.0") + finfo, err := os.Stat(file) + if err != nil { + t.Fatalf("error stating stdout file: %v", err) + } + time.Sleep(1 * time.Second) + finfo1, err := os.Stat(file) + if err != nil { + t.Fatalf("error stating stdout file: %v", err) + } + if finfo.Size() != finfo1.Size() { + t.Fatalf("Expected size: %v, actual: %v", finfo.Size(), finfo1.Size()) + } +} + func TestExecutor_Start_Kill(t *testing.T) { execCmd := ExecCommand{Cmd: "/bin/sleep", Args: []string{"10 && hello world"}} ctx := testExecutorContext(t)