Skip to content

Commit

Permalink
Merge pull request #5943 from hashicorp/b-allocrunner-killtimeout
Browse files Browse the repository at this point in the history
Populate task event struct with kill timeout
  • Loading branch information
preetapan committed Jul 10, 2019
2 parents 5b84adb + 7de4018 commit abc747d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions client/allocrunner/alloc_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
9 changes: 9 additions & 0 deletions client/allocrunner/alloc_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,25 @@ 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
}
}

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 {
Expand Down

0 comments on commit abc747d

Please sign in to comment.