Added a test which shows userpid is killed when plugin can not be re-connected on calling Open

This commit is contained in:
Diptanu Choudhury
2016-02-05 11:37:13 -08:00
parent b3d18a7a07
commit 1ba696abe5

View File

@@ -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)