scheduler: test job registration

This commit is contained in:
Armon Dadgar 2015-08-13 22:07:01 -07:00
parent e3f769f0ad
commit 6f62ceb2ae
3 changed files with 57 additions and 8 deletions

View File

@ -70,6 +70,7 @@ func Job() *structs.Job {
Type: structs.JobTypeService,
Priority: 50,
AllAtOnce: false,
Datacenters: []string{"dc1"},
Constraints: []*structs.Constraint{
&structs.Constraint{
Hard: true,

View File

@ -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
}

View File

@ -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) {