Skip to content

Commit

Permalink
Merge pull request #5788 from hashicorp/b-fix-node-down-test
Browse files Browse the repository at this point in the history
tests: Migrated allocs aren't lost
  • Loading branch information
Mahmood Ali authored Jun 6, 2019
2 parents 62ba654 + 5574b2f commit c15c763
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions scheduler/generic_sched_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2448,9 +2448,16 @@ func TestServiceSched_NodeDown(t *testing.T) {
}

// Mark appropriate allocs for migration
for i := 0; i < 7; i++ {
toBeMigrated := map[string]bool{}
for i := 0; i < 3; i++ {
out := allocs[i]
out.DesiredTransition.Migrate = helper.BoolToPtr(true)
toBeMigrated[out.ID] = true
}

toBeLost := map[string]bool{}
for i := len(toBeMigrated); i < 7; i++ {
toBeLost[allocs[i].ID] = true
}

noErr(t, h.State.UpsertAllocs(h.NextIndex(), allocs))
Expand All @@ -2469,25 +2476,28 @@ func TestServiceSched_NodeDown(t *testing.T) {

// Process the evaluation
err := h.Process(NewServiceScheduler, eval)
if err != nil {
t.Fatalf("err: %v", err)
}
require.NoError(t, err)

// Ensure a single plan
if len(h.Plans) != 1 {
t.Fatalf("bad: %#v", h.Plans)
}
require.Len(t, h.Plans, 1)
plan := h.Plans[0]

// Test the scheduler marked all non-terminal allocations as lost
if len(plan.NodeUpdate[node.ID]) != 7 {
t.Fatalf("bad: %#v", plan)
}
require.Len(t, plan.NodeUpdate[node.ID], len(toBeMigrated)+len(toBeLost))

for _, out := range plan.NodeUpdate[node.ID] {
if out.ClientStatus != structs.AllocClientStatusLost && out.DesiredStatus != structs.AllocDesiredStatusStop {
t.Fatalf("bad alloc: %#v", out)
}
t.Run("alloc "+out.ID, func(t *testing.T) {
require.Equal(t, structs.AllocDesiredStatusStop, out.DesiredStatus)

if toBeMigrated[out.ID] {
// there is no indicator on job itself that marks it as migrated
require.NotEqual(t, structs.AllocClientStatusLost, out.ClientStatus)
} else if toBeLost[out.ID] {
require.Equal(t, structs.AllocClientStatusLost, out.ClientStatus)
} else {
require.Fail(t, "unexpected alloc update")
}
})
}

h.AssertEvalStatus(t, structs.EvalStatusComplete)
Expand Down

0 comments on commit c15c763

Please sign in to comment.