From 8b2b3f99d3858757cfeda0b740333e54be153092 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Sun, 29 Mar 2020 17:56:10 -0400 Subject: [PATCH] tests: deflake TestHTTP_NodeDrain A node may be recognized as not running any allocs and have its drain flag reset before the test queries it. --- command/agent/node_endpoint_test.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/command/agent/node_endpoint_test.go b/command/agent/node_endpoint_test.go index 7a881be6a..f01d5be19 100644 --- a/command/agent/node_endpoint_test.go +++ b/command/agent/node_endpoint_test.go @@ -273,16 +273,26 @@ func TestHTTP_NodeDrain(t *testing.T) { require.NotZero(respW.HeaderMap.Get("X-Nomad-Index")) // Check the response - _, ok := obj.(structs.NodeDrainUpdateResponse) + dresp, ok := obj.(structs.NodeDrainUpdateResponse) require.True(ok) + t.Logf("response index=%v node_update_index=0x%x", respW.HeaderMap.Get("X-Nomad-Index"), + dresp.NodeModifyIndex) + // Check that the node has been updated state := s.Agent.server.State() out, err := state.NodeByID(nil, node.ID) require.Nil(err) - require.True(out.Drain) - require.NotNil(out.DrainStrategy) - require.Equal(10*time.Second, out.DrainStrategy.Deadline) + + // the node must either be in drain mode or in elligible + // once the node is recognize as not having any running allocs + if out.Drain { + require.True(out.Drain) + require.NotNil(out.DrainStrategy) + require.Equal(10*time.Second, out.DrainStrategy.Deadline) + } else { + require.Equal(structs.NodeSchedulingIneligible, out.SchedulingEligibility) + } // Make the HTTP request to unset drain drainReq.DrainSpec = nil