From 5bf43b50d4d7448b2b3b6a53d97613417f888747 Mon Sep 17 00:00:00 2001 From: Jasmine Dahilig Date: Thu, 9 Jan 2020 15:43:00 -0800 Subject: [PATCH] fix bug in lifecycle scheduler test mocks --- nomad/mock/mock.go | 18 +++++++++--------- scheduler/generic_sched_test.go | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/nomad/mock/mock.go b/nomad/mock/mock.go index 3fe0ee374..cd8394d0c 100644 --- a/nomad/mock/mock.go +++ b/nomad/mock/mock.go @@ -270,9 +270,9 @@ func Job() *structs.Job { return job } -func LifecycleSideTask(resources structs.Resources) *structs.Task { +func LifecycleSideTask(resources structs.Resources, i int) *structs.Task { return &structs.Task{ - Name: "sidecar", + Name: fmt.Sprintf("side-%s", i), Driver: "exec", Config: map[string]interface{}{ "command": "/bin/date", @@ -286,9 +286,9 @@ func LifecycleSideTask(resources structs.Resources) *structs.Task { } } -func LifecycleInitTask(resources structs.Resources) *structs.Task { +func LifecycleInitTask(resources structs.Resources, i int) *structs.Task { return &structs.Task{ - Name: "init", + Name: fmt.Sprintf("init-%s", i), Driver: "exec", Config: map[string]interface{}{ "command": "/bin/date", @@ -302,9 +302,9 @@ func LifecycleInitTask(resources structs.Resources) *structs.Task { } } -func LifecycleMainTask(resources structs.Resources) *structs.Task { +func LifecycleMainTask(resources structs.Resources, i int) *structs.Task { return &structs.Task{ - Name: "main", + Name: fmt.Sprintf("main-%s", i), Driver: "exec", Config: map[string]interface{}{ "command": "/bin/date", @@ -316,13 +316,13 @@ func LifecycleMainTask(resources structs.Resources) *structs.Task { func VariableLifecycleJob(resources structs.Resources, main int, init int, side int) *structs.Job { tasks := []*structs.Task{} for i := 0; i < main; i++ { - tasks = append(tasks, LifecycleMainTask(resources)) + tasks = append(tasks, LifecycleMainTask(resources, i)) } for i := 0; i < init; i++ { - tasks = append(tasks, LifecycleInitTask(resources)) + tasks = append(tasks, LifecycleInitTask(resources, i)) } for i := 0; i < side; i++ { - tasks = append(tasks, LifecycleSideTask(resources)) + tasks = append(tasks, LifecycleSideTask(resources, i)) } job := &structs.Job{ Region: "global", diff --git a/scheduler/generic_sched_test.go b/scheduler/generic_sched_test.go index 012259eaf..0223acebb 100644 --- a/scheduler/generic_sched_test.go +++ b/scheduler/generic_sched_test.go @@ -4406,9 +4406,6 @@ func TestGenericSched_AllocFit(t *testing.T) { SideTaskCount: 5, ShouldPlaceAlloc: true, }, - - // TODO: This test case currently places the allocation, - // but it should not be placed. Investigate placement. { Name: "too many init + sidecar", NodeCpu: 1200, @@ -4421,6 +4418,18 @@ func TestGenericSched_AllocFit(t *testing.T) { SideTaskCount: 10, ShouldPlaceAlloc: false, }, + { + Name: "too many too big", + NodeCpu: 1200, + TaskResources: structs.Resources{ + CPU: 1000, + MemoryMB: 100, + }, + MainTaskCount: 10, + InitTaskCount: 10, + SideTaskCount: 10, + ShouldPlaceAlloc: false, + }, } for _, testCase := range testCases { t.Run(testCase.Name, func(t *testing.T) {