From 0651341b1191769017afaf0475525cfe42bb0f5a Mon Sep 17 00:00:00 2001 From: Drew Bailey <2614075+drewbailey@users.noreply.github.com> Date: Tue, 28 Jan 2020 08:44:42 -0500 Subject: [PATCH] add a few more expectations --- nomad/state/state_store_test.go | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/nomad/state/state_store_test.go b/nomad/state/state_store_test.go index 2d682feda5b..1e8053ddfce 100644 --- a/nomad/state/state_store_test.go +++ b/nomad/state/state_store_test.go @@ -6413,6 +6413,44 @@ func TestStateStore_UpsertDeploymentAlloc_Canaries(t *testing.T) { // Ensure that PlacedCanaries is accurate require.Equal(t, 1, len(deploy.TaskGroups[job.TaskGroups[0].Name].PlacedCanaries)) + + // Create alloc without canary status + b := mock.Alloc() + b.JobID = job.ID + b.DeploymentID = d1.ID + b.DeploymentStatus = &structs.AllocDeploymentStatus{ + Healthy: helper.BoolToPtr(false), + Canary: false, + } + require.NoError(t, state.UpsertAllocs(4, []*structs.Allocation{b})) + + // Pull the deployment from state + ws = memdb.NewWatchSet() + deploy, err = state.DeploymentByID(ws, d1.ID) + require.NoError(t, err) + + // Ensure that PlacedCanaries is accurate + require.Equal(t, 1, len(deploy.TaskGroups[job.TaskGroups[0].Name].PlacedCanaries)) + + // Create a second deployment + d2 := mock.Deployment() + require.NoError(t, state.UpsertDeployment(5, d2)) + + c := mock.Alloc() + c.JobID = job.ID + c.DeploymentID = d2.ID + c.DeploymentStatus = &structs.AllocDeploymentStatus{ + Healthy: helper.BoolToPtr(false), + Canary: true, + } + require.NoError(t, state.UpsertAllocs(6, []*structs.Allocation{c})) + + ws = memdb.NewWatchSet() + deploy2, err := state.DeploymentByID(ws, d2.ID) + require.NoError(t, err) + + // Ensure that PlacedCanaries is accurate + require.Equal(t, 1, len(deploy2.TaskGroups[job.TaskGroups[0].Name].PlacedCanaries)) } func TestStateStore_UpsertDeploymentAlloc_NoCanaries(t *testing.T) {