From 26652d7a6b112c920656028533e5c7e25da923f2 Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Tue, 9 Jul 2019 09:37:09 -0500 Subject: [PATCH 1/2] Populate task event struct with kill timeout This makes for a nicer task event message --- client/allocrunner/alloc_runner.go | 8 ++++++-- client/allocrunner/alloc_runner_test.go | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/client/allocrunner/alloc_runner.go b/client/allocrunner/alloc_runner.go index 170dabe2442..1f93f2070b2 100644 --- a/client/allocrunner/alloc_runner.go +++ b/client/allocrunner/alloc_runner.go @@ -499,7 +499,9 @@ func (ar *allocRunner) killTasks() map[string]*structs.TaskState { continue } - err := tr.Kill(context.TODO(), structs.NewTaskEvent(structs.TaskKilling)) + taskEvent := structs.NewTaskEvent(structs.TaskKilling) + taskEvent.SetKillTimeout(tr.Task().KillTimeout) + err := tr.Kill(context.TODO(), taskEvent) if err != nil && err != taskrunner.ErrTaskNotRunning { ar.logger.Warn("error stopping leader task", "error", err, "task_name", name) } @@ -519,7 +521,9 @@ func (ar *allocRunner) killTasks() map[string]*structs.TaskState { wg.Add(1) go func(name string, tr *taskrunner.TaskRunner) { defer wg.Done() - err := tr.Kill(context.TODO(), structs.NewTaskEvent(structs.TaskKilling)) + taskEvent := structs.NewTaskEvent(structs.TaskKilling) + taskEvent.SetKillTimeout(tr.Task().KillTimeout) + err := tr.Kill(context.TODO(), taskEvent) if err != nil && err != taskrunner.ErrTaskNotRunning { ar.logger.Warn("error stopping task", "error", err, "task_name", name) } diff --git a/client/allocrunner/alloc_runner_test.go b/client/allocrunner/alloc_runner_test.go index e969a31c7c0..6b7d43dea5d 100644 --- a/client/allocrunner/alloc_runner_test.go +++ b/client/allocrunner/alloc_runner_test.go @@ -107,10 +107,19 @@ func TestAllocRunner_TaskLeader_KillTG(t *testing.T) { } found := false + killingMsg := "" for _, e := range state1.Events { if e.Type != structs.TaskLeaderDead { found = true } + if e.Type == structs.TaskKilling { + killingMsg = e.DisplayMessage + } + } + expectedKillingMsg := "Sent interrupt. Waiting 10ms before force killing" + + if killingMsg != expectedKillingMsg { + return false, fmt.Errorf("Unexpected task event message - wanted %q. got %q", killingMsg, expectedKillingMsg) } if !found { From 7de40186564c025733f7103f7f18defb91f6f1f0 Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Wed, 10 Jul 2019 10:41:06 -0500 Subject: [PATCH 2/2] code review feedback --- client/allocrunner/alloc_runner_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/allocrunner/alloc_runner_test.go b/client/allocrunner/alloc_runner_test.go index 6b7d43dea5d..5a758ce0a50 100644 --- a/client/allocrunner/alloc_runner_test.go +++ b/client/allocrunner/alloc_runner_test.go @@ -116,16 +116,16 @@ func TestAllocRunner_TaskLeader_KillTG(t *testing.T) { killingMsg = e.DisplayMessage } } - expectedKillingMsg := "Sent interrupt. Waiting 10ms before force killing" - - if killingMsg != expectedKillingMsg { - return false, fmt.Errorf("Unexpected task event message - wanted %q. got %q", killingMsg, expectedKillingMsg) - } if !found { return false, fmt.Errorf("Did not find event %v", structs.TaskLeaderDead) } + expectedKillingMsg := "Sent interrupt. Waiting 10ms before force killing" + if killingMsg != expectedKillingMsg { + return false, fmt.Errorf("Unexpected task event message - wanted %q. got %q", killingMsg, expectedKillingMsg) + } + // Task Two should be dead state2 := last.TaskStates[task2.Name] if state2.State != structs.TaskStateDead {