Skip to content

Commit

Permalink
Added a test for adjustQueuedAllocations
Browse files Browse the repository at this point in the history
  • Loading branch information
diptanu committed Jul 26, 2016
1 parent c91f477 commit a9c995b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion scheduler/generic_sched_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ func TestServiceSched_Plan_Partial_Progress(t *testing.T) {
node := mock.Node()
noErr(t, h.State.UpsertNode(h.NextIndex(), node))

// Create a job
// Create a job with a high resource ask so that all the allocations can't
// be placed on a single node.
job := mock.Job()
job.TaskGroups[0].Count = 3
job.TaskGroups[0].Tasks[0].Resources.CPU = 3600
Expand Down
34 changes: 34 additions & 0 deletions scheduler/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -913,3 +913,37 @@ func TestDesiredUpdates(t *testing.T) {
t.Fatalf("desiredUpdates() returned %#v; want %#v", desired, expected)
}
}

func TestUtil_AdjustQueuedAllocations(t *testing.T) {
logger := log.New(os.Stderr, "", log.LstdFlags)
alloc1 := mock.Alloc()
alloc2 := mock.Alloc()
alloc2.CreateIndex = 4
alloc3 := mock.Alloc()
alloc3.CreateIndex = 3
alloc4 := mock.Alloc()
alloc4.CreateIndex = 6

planResult := structs.PlanResult{
NodeUpdate: map[string][]*structs.Allocation{
"node-1": []*structs.Allocation{alloc1},
},
NodeAllocation: map[string][]*structs.Allocation{
"node-1": []*structs.Allocation{
alloc2,
},
"node-2": []*structs.Allocation{
alloc3, alloc4,
},
},
RefreshIndex: 3,
AllocIndex: 4,
}

queuedAllocs := map[string]int{"web": 2}
adjustQueuedAllocations(logger, &planResult, queuedAllocs)

if queuedAllocs["web"] != 1 {
t.Fatalf("expected: %v, actual: %v", 1, queuedAllocs["web"])
}
}

0 comments on commit a9c995b

Please sign in to comment.