Skip to content

Commit 2f4c131

Browse files
hc-github-team-nomad-coretgross
authored andcommitted
Backport of testing: fix flake in Agent.Host RPC handler test into release/1.10.x (#26913)
Co-authored-by: Tim Gross <[email protected]>
1 parent 2b16cce commit 2f4c131

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

nomad/client_agent_endpoint_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -840,10 +840,7 @@ func TestAgentHost_Server(t *testing.T) {
840840
defer cleanup()
841841

842842
TestJoin(t, s1, s2)
843-
testutil.WaitForLeader(t, s1.RPC)
844843
testutil.WaitForKeyring(t, s1.RPC, s1.Region())
845-
testutil.WaitForLeader(t, s2.RPC)
846-
testutil.WaitForKeyring(t, s2.RPC, s2.Region())
847844

848845
// determine leader and nonleader
849846
servers := []*Server{s1, s2}
@@ -865,9 +862,9 @@ func TestAgentHost_Server(t *testing.T) {
865862

866863
testutil.WaitForResult(func() (bool, error) {
867864
numNodes := len(s1.connectedNodes()) + len(s2.connectedNodes())
868-
return numNodes == 1, nil
865+
return numNodes > 0, nil
869866
}, func(err error) {
870-
t.Fatalf("should have a clients")
867+
t.Fatalf("client should be connected to a server")
871868
})
872869

873870
cases := []struct {
@@ -937,13 +934,14 @@ func TestAgentHost_Server(t *testing.T) {
937934

938935
err := tc.origin.RPC("Agent.Host", &req, &reply)
939936
if tc.expectedErr != "" {
940-
require.Contains(t, err.Error(), tc.expectedErr)
937+
must.ErrorContains(t, err, tc.expectedErr)
941938
} else {
942-
require.Nil(t, err)
943-
require.NotEmpty(t, reply.HostData)
939+
must.NoError(t, err)
940+
must.NotNil(t, reply.HostData)
944941
}
945942

946-
require.Equal(t, tc.expectedAgentID, reply.AgentID)
943+
// note: we expect this to be populated even on error
944+
must.Eq(t, tc.expectedAgentID, reply.AgentID)
947945
})
948946
}
949947
}

0 commit comments

Comments
 (0)