test: fix flaky test TestAPI_CatalogNodes (#13779)

This commit is contained in:
R.B. Boyer 2022-07-15 13:24:22 -05:00 committed by GitHub
parent bb4d4040fb
commit 0678bf91a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 33 deletions

View File

@ -36,19 +36,19 @@ func TestAPI_CatalogNodes(t *testing.T) {
s.WaitForSerfCheck(t) s.WaitForSerfCheck(t)
catalog := c.Catalog() catalog := c.Catalog()
retry.Run(t, func(r *retry.R) { retry.Run(t, func(r *retry.R) {
nodes, meta, err := catalog.Nodes(nil) nodes, meta, err := catalog.Nodes(nil)
// We're not concerned about the createIndex of an agent require.NoError(r, err)
// Hence we're setting it to the default value require.Len(r, nodes, 1)
nodes[0].CreateIndex = 0 require.True(r, meta.LastIndex >= 1, "Last index must be greater than 1")
if err != nil {
r.Fatal(err) // The raft indexes are not relevant for this test.
} got := nodes[0]
if meta.LastIndex < 2 { got.CreateIndex = 0
r.Fatal("Last index must be greater than 1") got.ModifyIndex = 0
}
want := []*Node{ want := &Node{
{
ID: s.Config.NodeID, ID: s.Config.NodeID,
Node: s.Config.NodeName, Node: s.Config.NodeName,
Partition: splitDefaultPartition, Partition: splitDefaultPartition,
@ -63,16 +63,8 @@ func TestAPI_CatalogNodes(t *testing.T) {
Meta: map[string]string{ Meta: map[string]string{
"consul-network-segment": "", "consul-network-segment": "",
}, },
// CreateIndex will never always be meta.LastIndex - 1
// The purpose of this test is not to test CreateIndex value of an agent
// rather to check if the client agent can get the correct number
// of agents with a particular service, KV pair, etc...
// Hence reverting this to the default value here.
CreateIndex: 0,
ModifyIndex: meta.LastIndex,
},
} }
require.Equal(r, want, nodes) require.Equal(r, want, got)
}) })
} }