Skip to content

Commit

Permalink
wip more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shoenig committed Oct 30, 2020
1 parent bf3f895 commit 20107fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
4 changes: 1 addition & 3 deletions nomad/structs/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 25 additions & 6 deletions scheduler/system_sysbatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 20107fa

Please sign in to comment.