fix bug in lifecycle scheduler test mocks

This commit is contained in:
Jasmine Dahilig
2020-01-09 15:43:00 -08:00
committed by Mahmood Ali
parent c6cd7b523b
commit 5bf43b50d4
2 changed files with 21 additions and 12 deletions

View File

@@ -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",

View File

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