scheduler: test job registration
This commit is contained in:
parent
e3f769f0ad
commit
6f62ceb2ae
|
@ -70,6 +70,7 @@ func Job() *structs.Job {
|
||||||
Type: structs.JobTypeService,
|
Type: structs.JobTypeService,
|
||||||
Priority: 50,
|
Priority: 50,
|
||||||
AllAtOnce: false,
|
AllAtOnce: false,
|
||||||
|
Datacenters: []string{"dc1"},
|
||||||
Constraints: []*structs.Constraint{
|
Constraints: []*structs.Constraint{
|
||||||
&structs.Constraint{
|
&structs.Constraint{
|
||||||
Hard: true,
|
Hard: true,
|
||||||
|
|
|
@ -175,8 +175,8 @@ func (s *ServiceScheduler) computePlacements(job *structs.Job, place []allocTupl
|
||||||
for _, missing := range place {
|
for _, missing := range place {
|
||||||
option, size := stack.Select(missing.TaskGroup)
|
option, size := stack.Select(missing.TaskGroup)
|
||||||
if option == nil {
|
if option == nil {
|
||||||
s.logger.Printf("[DEBUG] sched: %#v: failed to place alloc %s",
|
s.logger.Printf("[DEBUG] sched: %#v: failed to place alloc %s: %#v",
|
||||||
s.eval, missing)
|
s.eval, missing.Name, ctx.Metrics())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,55 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServiceSched_JobRegister(t *testing.T) {
|
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) {
|
func TestServiceSched_JobModify(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue