From 1ba696abe58966fc7a00cfc1cf7ca7cfb5e854fe Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Fri, 5 Feb 2016 11:37:13 -0800 Subject: [PATCH] Added a test which shows userpid is killed when plugin can not be re-connected on calling Open --- client/driver/exec_test.go | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/client/driver/exec_test.go b/client/driver/exec_test.go index e7189f1fc..a9f941b9b 100644 --- a/client/driver/exec_test.go +++ b/client/driver/exec_test.go @@ -1,8 +1,10 @@ package driver import ( + "encoding/json" "fmt" "io/ioutil" + "os" "path/filepath" "reflect" "testing" @@ -75,6 +77,56 @@ func TestExecDriver_StartOpen_Wait(t *testing.T) { handle2.Kill() } +func TestExecDriver_KillUserPid_OnPluginReconnectFailure(t *testing.T) { + t.Parallel() + ctestutils.ExecCompatible(t) + task := &structs.Task{ + Name: "sleep", + Config: map[string]interface{}{ + "command": "/bin/sleep", + "args": []string{"1000000"}, + }, + Resources: basicResources, + } + + driverCtx, execCtx := testDriverContexts(task) + defer execCtx.AllocDir.Destroy() + d := NewExecDriver(driverCtx) + + handle, err := d.Start(execCtx, task) + defer handle.Kill() + if err != nil { + t.Fatalf("err: %v", err) + } + if handle == nil { + t.Fatalf("missing handle") + } + + id := &execId{} + if err := json.Unmarshal([]byte(handle.ID()), id); err != nil { + t.Fatalf("Failed to parse handle '%s': %v", handle.ID(), err) + } + pluginPid := id.PluginConfig.Pid + proc, err := os.FindProcess(pluginPid) + if err != nil { + t.Fatalf("can't find plugin pid: %v", pluginPid) + } + if err := proc.Kill(); err != nil { + t.Fatalf("can't kill plugin pid: %v", err) + } + + // Attempt to open + handle2, err := d.Open(execCtx, handle.ID()) + userProc, err := os.FindProcess(id.UserPid) + if err := userProc.Kill(); err == nil { + t.Fatalf("user process is supposed to be killed when plugin exits") + } + if handle2 != nil { + defer handle2.Kill() + t.Fatalf("expected handle2 to be nil") + } +} + func TestExecDriver_Start_Wait(t *testing.T) { t.Parallel() ctestutils.ExecCompatible(t)