From 39bcfcd1c646eff9de7a7ba63fa063330600d5ac Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Fri, 22 Jul 2016 11:56:03 -0700 Subject: [PATCH] Added a test to ensure system scheduler records the correct number of queued allocations --- scheduler/system_sched_test.go | 57 ++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/scheduler/system_sched_test.go b/scheduler/system_sched_test.go index 1e3009826..9ee69d48a 100644 --- a/scheduler/system_sched_test.go +++ b/scheduler/system_sched_test.go @@ -70,9 +70,66 @@ func TestSystemSched_JobRegister(t *testing.T) { t.Fatalf("bad: %#v", out[0].Metrics) } + // Ensure no allocations are queued + queued := h.Evals[0].QueuedAllocations["web"] + if queued != 0 { + t.Fatalf("expected queued allocations: %v, actual: %v", 0, queued) + } + h.AssertEvalStatus(t, structs.EvalStatusComplete) } +func TestSystemSched_ExhaustResources(t *testing.T) { + h := NewHarness(t) + + // Create a nodes + node := mock.Node() + noErr(t, h.State.UpsertNode(h.NextIndex(), node)) + + // Create a service job which consumes most of the system resources + svcJob := mock.Job() + svcJob.TaskGroups[0].Count = 1 + svcJob.TaskGroups[0].Tasks[0].Resources.CPU = 3600 + noErr(t, h.State.UpsertJob(h.NextIndex(), svcJob)) + + // Create a mock evaluation to register the job + eval := &structs.Evaluation{ + ID: structs.GenerateUUID(), + Priority: svcJob.Priority, + TriggeredBy: structs.EvalTriggerJobRegister, + JobID: svcJob.ID, + } + + // Process the evaluation + err := h.Process(NewServiceScheduler, eval) + if err != nil { + t.Fatalf("err: %v", err) + } + + // Create a system job + job := mock.SystemJob() + noErr(t, h.State.UpsertJob(h.NextIndex(), job)) + + // Create a mock evaluation to register the job + eval1 := &structs.Evaluation{ + ID: structs.GenerateUUID(), + Priority: job.Priority, + TriggeredBy: structs.EvalTriggerJobRegister, + JobID: job.ID, + } + + // Process the evaluation + if err := h.Process(NewSystemScheduler, eval1); err != nil { + t.Fatalf("err: %v", err) + } + + // Ensure that we have one allocation queued from the system job eval + queued := h.Evals[1].QueuedAllocations["web"] + if queued != 1 { + t.Fatalf("expected: %v, actual: %v", 1, queued) + } +} + func TestSystemSched_JobRegister_Annotate(t *testing.T) { h := NewHarness(t)