diff --git a/nomad/mock/mock.go b/nomad/mock/mock.go index db8b40a1e..fd30de01c 100644 --- a/nomad/mock/mock.go +++ b/nomad/mock/mock.go @@ -65,11 +65,12 @@ func Node() *structs.Node { func Job() *structs.Job { job := &structs.Job{ - ID: GenerateUUID(), - Name: "my-job", - Type: structs.JobTypeService, - Priority: 50, - AllAtOnce: false, + ID: GenerateUUID(), + Name: "my-job", + Type: structs.JobTypeService, + Priority: 50, + AllAtOnce: false, + Datacenters: []string{"dc1"}, Constraints: []*structs.Constraint{ &structs.Constraint{ Hard: true, diff --git a/scheduler/service_sched.go b/scheduler/service_sched.go index 4845f9309..c20ca55e7 100644 --- a/scheduler/service_sched.go +++ b/scheduler/service_sched.go @@ -175,8 +175,8 @@ func (s *ServiceScheduler) computePlacements(job *structs.Job, place []allocTupl for _, missing := range place { option, size := stack.Select(missing.TaskGroup) if option == nil { - s.logger.Printf("[DEBUG] sched: %#v: failed to place alloc %s", - s.eval, missing) + s.logger.Printf("[DEBUG] sched: %#v: failed to place alloc %s: %#v", + s.eval, missing.Name, ctx.Metrics()) continue } diff --git a/scheduler/service_sched_test.go b/scheduler/service_sched_test.go index cdcdb2fcf..5d6061934 100644 --- a/scheduler/service_sched_test.go +++ b/scheduler/service_sched_test.go @@ -8,7 +8,55 @@ import ( ) func TestServiceSched_JobRegister(t *testing.T) { - // TODO + h := NewHarness(t) + + // Create some nodes + for i := 0; i < 10; i++ { + node := mock.Node() + noErr(t, h.State.RegisterNode(h.NextIndex(), node)) + } + + // Create a job + job := mock.Job() + noErr(t, h.State.RegisterJob(h.NextIndex(), job)) + + // Create a mock evaluation to deregister the job + eval := &structs.Evaluation{ + ID: mock.GenerateUUID(), + Priority: job.Priority, + TriggeredBy: structs.EvalTriggerJobRegister, + JobID: job.ID, + } + + // Process the evaluation + err := h.Process(NewServiceScheduler, eval) + if err != nil { + t.Fatalf("err: %v", err) + } + + // Ensure a single plan + if len(h.Plans) != 1 { + t.Fatalf("bad: %#v", h.Plans) + } + plan := h.Plans[0] + + // Ensure the plan evicted all nodes + var planned []*structs.Allocation + for _, allocList := range plan.NodeAllocation { + planned = append(planned, allocList...) + } + if len(planned) != 10 { + t.Fatalf("bad: %#v", plan) + } + + // Lookup the allocations by JobID + out, err := h.State.AllocsByJob(job.ID) + noErr(t, err) + + // Ensure all allocations placed + if len(out) != 10 { + t.Fatalf("bad: %#v", out) + } } func TestServiceSched_JobModify(t *testing.T) {