Skip to content

Commit

Permalink
tests: use GreaterOrEqual and apply change to other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmood Ali committed May 27, 2020
1 parent 35d039e commit 74af591
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions nomad/drainer_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ func TestDrainer_Simple_ServiceOnly(t *testing.T) {
// Check we got the right events
node, err := state.NodeByID(nil, n1.ID)
require.NoError(err)
require.Len(node.Events, 3)
// sometimes test gets a duplicate node drain complete event
require.GreaterOrEqualf(len(node.Events), 3, "unexpected number of events: %v", node.Events)
require.Equal(drainer.NodeDrainEventComplete, node.Events[2].Message)
}

Expand Down Expand Up @@ -314,7 +315,8 @@ func TestDrainer_Simple_ServiceOnly_Deadline(t *testing.T) {
// Check we got the right events
node, err := state.NodeByID(nil, n1.ID)
require.NoError(err)
require.Len(node.Events, 3)
// sometimes test gets a duplicate node drain complete event
require.GreaterOrEqualf(len(node.Events), 3, "unexpected number of events: %v", node.Events)
require.Equal(drainer.NodeDrainEventComplete, node.Events[2].Message)
require.Contains(node.Events[2].Details, drainer.NodeDrainEventDetailDeadlined)
}
Expand Down Expand Up @@ -365,7 +367,8 @@ func TestDrainer_DrainEmptyNode(t *testing.T) {
// Check we got the right events
node, err := state.NodeByID(nil, n1.ID)
require.NoError(err)
require.Len(node.Events, 3)
// sometimes test gets a duplicate node drain complete event
require.GreaterOrEqualf(len(node.Events), 3, "unexpected number of events: %v", node.Events)
require.Equal(drainer.NodeDrainEventComplete, node.Events[2].Message)
}

Expand Down Expand Up @@ -529,7 +532,8 @@ func TestDrainer_AllTypes_Deadline(t *testing.T) {
// Check we got the right events
node, err := state.NodeByID(nil, n1.ID)
require.NoError(err)
require.Len(node.Events, 3)
// sometimes test gets a duplicate node drain complete event
require.GreaterOrEqualf(len(node.Events), 3, "unexpected number of events: %v", node.Events)
require.Equal(drainer.NodeDrainEventComplete, node.Events[2].Message)
require.Contains(node.Events[2].Details, drainer.NodeDrainEventDetailDeadlined)
}
Expand Down Expand Up @@ -698,9 +702,7 @@ func TestDrainer_AllTypes_NoDeadline(t *testing.T) {
require.NoError(err)

// sometimes test gets a duplicate node drain complete event
if len(node.Events) < 3 {
require.Len(node.Events, 3, "expected at least 3 events")
}
require.GreaterOrEqualf(len(node.Events), 3, "unexpected number of events: %v", node.Events)
require.Equal(drainer.NodeDrainEventComplete, node.Events[2].Message)
}

Expand Down Expand Up @@ -872,7 +874,8 @@ func TestDrainer_AllTypes_Deadline_GarbageCollectedNode(t *testing.T) {
// Check we got the right events
node, err := state.NodeByID(nil, n1.ID)
require.NoError(err)
require.Len(node.Events, 3)
// sometimes test gets a duplicate node drain complete event
require.GreaterOrEqualf(len(node.Events), 3, "unexpected number of events: %v", node.Events)
require.Equal(drainer.NodeDrainEventComplete, node.Events[2].Message)
require.Contains(node.Events[2].Details, drainer.NodeDrainEventDetailDeadlined)
}
Expand Down Expand Up @@ -1017,7 +1020,8 @@ func TestDrainer_Batch_TransitionToForce(t *testing.T) {
// Check we got the right events
node, err := state.NodeByID(nil, n1.ID)
require.NoError(err)
require.Len(node.Events, 4)
// sometimes test gets a duplicate node drain complete event
require.GreaterOrEqualf(len(node.Events), 4, "unexpected number of events: %v", node.Events)
require.Equal(drainer.NodeDrainEventComplete, node.Events[3].Message)
require.Contains(node.Events[3].Details, drainer.NodeDrainEventDetailDeadlined)
})
Expand Down

0 comments on commit 74af591

Please sign in to comment.