diff --git a/nomad/structs/funcs.go b/nomad/structs/funcs.go index a3b442c7b371..eb19000eefbc 100644 --- a/nomad/structs/funcs.go +++ b/nomad/structs/funcs.go @@ -70,9 +70,7 @@ func RemoveAllocs(alloc []*Allocation, remove []*Allocation) []*Allocation { } // FilterTerminalAllocs filters out all allocations in a terminal state and -// returns the latest terminal allocations -// -// Deprecated: use scheduler.SplitTerminalAllocs +// returns the latest terminal allocations. func FilterTerminalAllocs(allocs []*Allocation) ([]*Allocation, map[string]*Allocation) { terminalAllocsByName := make(map[string]*Allocation) n := len(allocs) diff --git a/scheduler/system_sysbatch_test.go b/scheduler/system_sysbatch_test.go index c5d0c78e8318..13a42a417595 100644 --- a/scheduler/system_sysbatch_test.go +++ b/scheduler/system_sysbatch_test.go @@ -165,7 +165,7 @@ func TestSysBatch_JobRegister_AddNode_Dead(t *testing.T) { // Generate a dead sysbatch job with complete allocations job := mock.SystemBatchJob() - job.Status = structs.JobStatusDead + job.Status = structs.JobStatusDead // job is dead but not stopped require.NoError(t, h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job)) var allocs []*structs.Allocation @@ -199,17 +199,36 @@ func TestSysBatch_JobRegister_AddNode_Dead(t *testing.T) { err := h.Process(NewSysBatchScheduler, eval) require.NoError(t, err) - // Ensure no plan (nothing to do) - require.Len(t, h.Plans, 0) + // Ensure a single plan + require.Len(t, h.Plans, 1) + plan := h.Plans[0] + + // Ensure the plan has no node update + var update []*structs.Allocation + for _, updateList := range plan.NodeUpdate { + update = append(update, updateList...) + } + require.Len(t, update, 0) + + // Ensure the plan allocates on the new node + var planned []*structs.Allocation + for _, allocList := range plan.NodeAllocation { + planned = append(planned, allocList...) + } + require.Len(t, planned, 1) + + // Ensure it allocated on the right node + _, ok := plan.NodeAllocation[node.ID] + require.True(t, ok, "allocated on wrong node: %#v", plan) // Lookup the allocations by JobID ws := memdb.NewWatchSet() out, err := h.State.AllocsByJob(ws, job.Namespace, job.ID, false) require.NoError(t, err) - // Ensure no non-terminal allocations - out, _ = structs.FilterTerminalAllocs(out) - require.Empty(t, out) + // Ensure 1 non-terminal allocation + live, _ := structs.FilterTerminalAllocs(out) + require.Len(t, live, 1) h.AssertEvalStatus(t, structs.EvalStatusComplete) }