From 61e4f5aaf9c91253e51bbf8293aac20e28d3d3fe Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Wed, 27 May 2020 10:10:13 -0400 Subject: [PATCH] tests: use GreaterOrEqual and apply change to other tests --- nomad/drainer_int_test.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/nomad/drainer_int_test.go b/nomad/drainer_int_test.go index 0ff06280e..ce480bd33 100644 --- a/nomad/drainer_int_test.go +++ b/nomad/drainer_int_test.go @@ -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) } @@ -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) } @@ -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) } @@ -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) } @@ -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) } @@ -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) } @@ -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) })