Fix raw exec test race condition

This commit is contained in:
Alex Dadgar
2015-10-09 20:56:28 -07:00
parent 9514cde6b8
commit 75eb9e28d8

View File

@@ -52,7 +52,7 @@ func TestRawExecDriver_StartOpen_Wait(t *testing.T) {
Name: "sleep",
Config: map[string]string{
"command": "/bin/sleep",
"args": "2",
"args": "1",
},
}
driverCtx := testDriverContext(task.Name)
@@ -70,7 +70,6 @@ func TestRawExecDriver_StartOpen_Wait(t *testing.T) {
// Attempt to open
handle2, err := d.Open(ctx, handle.ID())
handle2.(*rawExecHandle).waitCh = make(chan error, 1)
if err != nil {
t.Fatalf("err: %v", err)
}
@@ -80,13 +79,17 @@ func TestRawExecDriver_StartOpen_Wait(t *testing.T) {
// Task should terminate quickly
select {
case err := <-handle2.WaitCh():
if err != nil {
t.Fatalf("err: %v", err)
}
case <-time.After(3 * time.Second):
case <-handle2.WaitCh():
case <-time.After(2 * time.Second):
t.Fatalf("timeout")
}
// Check they are both tracking the same PID.
pid1 := handle.(*rawExecHandle).proc.Pid
pid2 := handle2.(*rawExecHandle).proc.Pid
if pid1 != pid2 {
t.Fatalf("tracking incorrect Pid; %v != %v", pid1, pid2)
}
}
func TestRawExecDriver_Start_Wait(t *testing.T) {