From 139d2e7939d581c42bf91470cd24559db88ffe76 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Thu, 25 Aug 2016 16:05:19 -0700 Subject: [PATCH] Ensure bad task reaches terminal state within test --- client/alloc_runner_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/client/alloc_runner_test.go b/client/alloc_runner_test.go index d8b48b705..c6003a296 100644 --- a/client/alloc_runner_test.go +++ b/client/alloc_runner_test.go @@ -71,6 +71,7 @@ func TestAllocRunner_RetryArtifact(t *testing.T) { alloc := mock.Alloc() alloc.Job.Type = structs.JobTypeBatch + alloc.Job.TaskGroups[0].RestartPolicy.Attempts = 0 // Create a new task with a bad artifact badtask := alloc.Job.TaskGroups[0].Tasks[0].Copy() @@ -89,6 +90,9 @@ func TestAllocRunner_RetryArtifact(t *testing.T) { return false, fmt.Errorf("Not enough updates") } last := upd.Allocs[upd.Count-1] + + // web task should have completed successfully while bad task + // retries artififact fetching webstate := last.TaskStates["web"] if webstate.State != structs.TaskStateDead { return false, fmt.Errorf("expected web to be dead but found %q", last.TaskStates["web"].State) @@ -96,8 +100,14 @@ func TestAllocRunner_RetryArtifact(t *testing.T) { if !webstate.Successful() { return false, fmt.Errorf("expected web to have exited successfully") } - if last.TaskStates["bad"].State != structs.TaskStatePending { - return false, fmt.Errorf("expected bad to be pending but found %q", last.TaskStates["web"].State) + + // bad task should have failed + badstate := last.TaskStates["bad"] + if badstate.State != structs.TaskStateDead { + return false, fmt.Errorf("expected bad to be dead but found %q", last.TaskStates["web"].State) + } + if !badstate.Failed() { + return false, fmt.Errorf("expected bad to have failed") } return true, nil }, func(err error) {