Skip to content

Commit a9c995b

Browse files
committed
Added a test for adjustQueuedAllocations
1 parent c91f477 commit a9c995b

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

scheduler/generic_sched_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ func TestServiceSched_Plan_Partial_Progress(t *testing.T) {
502502
node := mock.Node()
503503
noErr(t, h.State.UpsertNode(h.NextIndex(), node))
504504

505-
// Create a job
505+
// Create a job with a high resource ask so that all the allocations can't
506+
// be placed on a single node.
506507
job := mock.Job()
507508
job.TaskGroups[0].Count = 3
508509
job.TaskGroups[0].Tasks[0].Resources.CPU = 3600

scheduler/util_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -913,3 +913,37 @@ func TestDesiredUpdates(t *testing.T) {
913913
t.Fatalf("desiredUpdates() returned %#v; want %#v", desired, expected)
914914
}
915915
}
916+
917+
func TestUtil_AdjustQueuedAllocations(t *testing.T) {
918+
logger := log.New(os.Stderr, "", log.LstdFlags)
919+
alloc1 := mock.Alloc()
920+
alloc2 := mock.Alloc()
921+
alloc2.CreateIndex = 4
922+
alloc3 := mock.Alloc()
923+
alloc3.CreateIndex = 3
924+
alloc4 := mock.Alloc()
925+
alloc4.CreateIndex = 6
926+
927+
planResult := structs.PlanResult{
928+
NodeUpdate: map[string][]*structs.Allocation{
929+
"node-1": []*structs.Allocation{alloc1},
930+
},
931+
NodeAllocation: map[string][]*structs.Allocation{
932+
"node-1": []*structs.Allocation{
933+
alloc2,
934+
},
935+
"node-2": []*structs.Allocation{
936+
alloc3, alloc4,
937+
},
938+
},
939+
RefreshIndex: 3,
940+
AllocIndex: 4,
941+
}
942+
943+
queuedAllocs := map[string]int{"web": 2}
944+
adjustQueuedAllocations(logger, &planResult, queuedAllocs)
945+
946+
if queuedAllocs["web"] != 1 {
947+
t.Fatalf("expected: %v, actual: %v", 1, queuedAllocs["web"])
948+
}
949+
}

0 commit comments

Comments
 (0)