Skip to content

Commit

Permalink
update tests to match expected behavior of waiting for client status
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed Aug 30, 2022
1 parent 52aac9b commit 6b056d2
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion nomad/drainer/watch_jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,17 @@ func TestDrainingJobWatcher_DrainJobs(t *testing.T) {

// Proceed our fake migration along by creating new allocs and stopping
// old ones
//
// TODO: extend this test so that it exercises the behavior when we get a
// server stop first, followed by a client stop
//
replacements := make([]*structs.Allocation, len(drainedAllocs))
updates := make([]*structs.Allocation, 0, len(drainedAllocs)*2)
for i, a := range drainedAllocs {
// Stop drained allocs
a.DesiredTransition.Migrate = nil
a.DesiredStatus = structs.AllocDesiredStatusStop
a.ClientStatus = structs.AllocClientStatusComplete

// Create a replacement
replacement := mock.Alloc()
Expand Down Expand Up @@ -233,6 +238,7 @@ func TestDrainingJobWatcher_DrainJobs(t *testing.T) {
for i, a := range drainedAllocs {
a.DesiredTransition.Migrate = nil
a.DesiredStatus = structs.AllocDesiredStatusStop
a.ClientStatus = structs.AllocClientStatusComplete

replacement := newAlloc(runningNode, a.Job)
updates = append(updates, a, replacement)
Expand Down Expand Up @@ -276,6 +282,7 @@ func TestDrainingJobWatcher_DrainJobs(t *testing.T) {
for i, a := range drainedAllocs {
a.DesiredTransition.Migrate = nil
a.DesiredStatus = structs.AllocDesiredStatusStop
a.ClientStatus = structs.AllocClientStatusComplete

replacement := newAlloc(runningNode, a.Job)
updates = append(updates, a, replacement)
Expand Down Expand Up @@ -328,7 +335,7 @@ type handleTaskGroupTestCase struct {
AddAlloc func(i int, a *structs.Allocation, drainingID, runningID string)
}

func TestHandeTaskGroup_Table(t *testing.T) {
func TestHandleTaskGroup_Table(t *testing.T) {
ci.Parallel(t)

cases := []handleTaskGroupTestCase{
Expand Down Expand Up @@ -397,6 +404,7 @@ func TestHandeTaskGroup_Table(t *testing.T) {
AddAlloc: func(i int, a *structs.Allocation, drainingID, runningID string) {
if i == 0 {
a.DesiredStatus = structs.AllocDesiredStatusStop
a.ClientStatus = structs.AllocClientStatusComplete
return
}
a.NodeID = runningID
Expand All @@ -412,6 +420,7 @@ func TestHandeTaskGroup_Table(t *testing.T) {
AddAlloc: func(i int, a *structs.Allocation, drainingID, runningID string) {
if i == 0 {
a.DesiredStatus = structs.AllocDesiredStatusStop
a.ClientStatus = structs.AllocClientStatusComplete
return
}
a.NodeID = runningID
Expand All @@ -425,6 +434,7 @@ func TestHandeTaskGroup_Table(t *testing.T) {
ExpectedDone: true,
AddAlloc: func(i int, a *structs.Allocation, drainingID, runningID string) {
a.DesiredStatus = structs.AllocDesiredStatusStop
a.ClientStatus = structs.AllocClientStatusComplete
},
},
{
Expand All @@ -436,6 +446,7 @@ func TestHandeTaskGroup_Table(t *testing.T) {
ExpectedDone: true,
AddAlloc: func(i int, a *structs.Allocation, drainingID, runningID string) {
a.DesiredStatus = structs.AllocDesiredStatusStop
a.ClientStatus = structs.AllocClientStatusComplete
},
},
{
Expand All @@ -456,6 +467,7 @@ func TestHandeTaskGroup_Table(t *testing.T) {
},
{
// One on new node, one drained, and one draining
Name: "OneOnNew_OneDrained_OneDraining",
ExpectedDrained: 1,
ExpectedMigrated: 1,
MaxParallel: 2,
Expand All @@ -472,6 +484,7 @@ func TestHandeTaskGroup_Table(t *testing.T) {
},
{
// 8 on new node, one drained, and one draining
Name: "8OnNew_OneDrained_OneDraining",
ExpectedDrained: 1,
ExpectedMigrated: 1,
MaxParallel: 2,
Expand All @@ -486,6 +499,7 @@ func TestHandeTaskGroup_Table(t *testing.T) {
},
{
// 5 on new node, two drained, and three draining
Name: "5OnNew_2Drained_3Draining",
ExpectedDrained: 3,
ExpectedMigrated: 2,
MaxParallel: 5,
Expand Down Expand Up @@ -635,6 +649,7 @@ func TestHandleTaskGroup_Migrations(t *testing.T) {

if i%2 == 0 {
a.DesiredStatus = structs.AllocDesiredStatusStop
a.ClientStatus = structs.AllocClientStatusComplete
} else {
a.ClientStatus = structs.AllocClientStatusFailed
}
Expand Down Expand Up @@ -704,6 +719,7 @@ func TestHandleTaskGroup_GarbageCollectedNode(t *testing.T) {

if i%2 == 0 {
a.DesiredStatus = structs.AllocDesiredStatusStop
a.ClientStatus = structs.AllocClientStatusComplete
} else {
a.ClientStatus = structs.AllocClientStatusFailed
}
Expand Down

0 comments on commit 6b056d2

Please sign in to comment.