From be30f029134bdd8aa262b71bb10d665b270aec79 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Thu, 19 Apr 2018 16:11:57 -0700 Subject: [PATCH] Fix tests --- nomad/deployment_endpoint_test.go | 8 ++++---- nomad/deploymentwatcher/deployments_watcher_test.go | 10 ++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/nomad/deployment_endpoint_test.go b/nomad/deployment_endpoint_test.go index 97e0ae416..fa9ca5f86 100644 --- a/nomad/deployment_endpoint_test.go +++ b/nomad/deployment_endpoint_test.go @@ -472,9 +472,9 @@ func TestDeploymentEndpoint_Promote(t *testing.T) { j := mock.Job() j.TaskGroups[0].Update = structs.DefaultUpdateStrategy.Copy() j.TaskGroups[0].Update.MaxParallel = 2 - j.TaskGroups[0].Update.Canary = 2 + j.TaskGroups[0].Update.Canary = 1 d := mock.Deployment() - d.TaskGroups["web"].DesiredCanaries = 2 + d.TaskGroups["web"].DesiredCanaries = 1 d.JobID = j.ID a := mock.Alloc() d.TaskGroups[a.TaskGroup].PlacedCanaries = []string{a.ID} @@ -536,9 +536,9 @@ func TestDeploymentEndpoint_Promote_ACL(t *testing.T) { j := mock.Job() j.TaskGroups[0].Update = structs.DefaultUpdateStrategy.Copy() j.TaskGroups[0].Update.MaxParallel = 2 - j.TaskGroups[0].Update.Canary = 2 + j.TaskGroups[0].Update.Canary = 1 d := mock.Deployment() - d.TaskGroups["web"].DesiredCanaries = 2 + d.TaskGroups["web"].DesiredCanaries = 1 d.JobID = j.ID a := mock.Alloc() d.TaskGroups[a.TaskGroup].PlacedCanaries = []string{a.ID} diff --git a/nomad/deploymentwatcher/deployments_watcher_test.go b/nomad/deploymentwatcher/deployments_watcher_test.go index 437a59590..1d072d561 100644 --- a/nomad/deploymentwatcher/deployments_watcher_test.go +++ b/nomad/deploymentwatcher/deployments_watcher_test.go @@ -391,11 +391,12 @@ func TestWatcher_PromoteDeployment_HealthyCanaries(t *testing.T) { j := mock.Job() j.TaskGroups[0].Update = structs.DefaultUpdateStrategy.Copy() j.TaskGroups[0].Update.MaxParallel = 2 - j.TaskGroups[0].Update.Canary = 2 + j.TaskGroups[0].Update.Canary = 1 j.TaskGroups[0].Update.ProgressDeadline = 0 d := mock.Deployment() d.JobID = j.ID a := mock.Alloc() + d.TaskGroups[a.TaskGroup].DesiredCanaries = 1 d.TaskGroups[a.TaskGroup].PlacedCanaries = []string{a.ID} a.DeploymentStatus = &structs.AllocDeploymentStatus{ Healthy: helper.BoolToPtr(true), @@ -416,6 +417,10 @@ func TestWatcher_PromoteDeployment_HealthyCanaries(t *testing.T) { matcher := matchDeploymentPromoteRequest(matchConfig) m.On("UpdateDeploymentPromotion", mocker.MatchedBy(matcher)).Return(nil) + // We may get an update for the desired transistion. + m1 := matchUpdateAllocDesiredTransitions([]string{d.ID}) + m.On("UpdateAllocDesiredTransition", mocker.MatchedBy(m1)).Return(nil).Once() + w.SetEnabled(true, m.state) testutil.WaitForResult(func() (bool, error) { return 1 == len(w.watchers), nil }, func(err error) { assert.Equal(1, len(w.watchers), "Should have 1 deployment") }) @@ -448,6 +453,7 @@ func TestWatcher_PromoteDeployment_UnhealthyCanaries(t *testing.T) { d.JobID = j.ID a := mock.Alloc() d.TaskGroups[a.TaskGroup].PlacedCanaries = []string{a.ID} + d.TaskGroups[a.TaskGroup].DesiredCanaries = 2 a.DeploymentID = d.ID assert.Nil(m.state.UpsertJob(m.nextIndex(), j), "UpsertJob") assert.Nil(m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment") @@ -476,7 +482,7 @@ func TestWatcher_PromoteDeployment_UnhealthyCanaries(t *testing.T) { var resp structs.DeploymentUpdateResponse err := w.PromoteDeployment(req, &resp) if assert.NotNil(err, "PromoteDeployment") { - assert.Contains(err.Error(), "is not healthy", "Should error because canary isn't marked healthy") + assert.Contains(err.Error(), `Task group "web" has 0/2 healthy allocations`, "Should error because canary isn't marked healthy") } assert.Equal(1, len(w.watchers), "Deployment should still be active")