Browse Source

test: fix flaky test TestAPI_CatalogNodes (#13779)

pull/13781/head
R.B. Boyer 2 years ago committed by GitHub
parent
commit
0678bf91a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 58
      api/catalog_test.go

58
api/catalog_test.go

@ -36,43 +36,35 @@ func TestAPI_CatalogNodes(t *testing.T) {
s.WaitForSerfCheck(t)
catalog := c.Catalog()
retry.Run(t, func(r *retry.R) {
nodes, meta, err := catalog.Nodes(nil)
// We're not concerned about the createIndex of an agent
// Hence we're setting it to the default value
nodes[0].CreateIndex = 0
if err != nil {
r.Fatal(err)
}
if meta.LastIndex < 2 {
r.Fatal("Last index must be greater than 1")
}
want := []*Node{
{
ID: s.Config.NodeID,
Node: s.Config.NodeName,
Partition: splitDefaultPartition,
Address: "127.0.0.1",
Datacenter: "dc1",
TaggedAddresses: map[string]string{
"lan": "127.0.0.1",
"lan_ipv4": "127.0.0.1",
"wan": "127.0.0.1",
"wan_ipv4": "127.0.0.1",
},
Meta: map[string]string{
"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.NoError(r, err)
require.Len(r, nodes, 1)
require.True(r, meta.LastIndex >= 1, "Last index must be greater than 1")
// The raft indexes are not relevant for this test.
got := nodes[0]
got.CreateIndex = 0
got.ModifyIndex = 0
want := &Node{
ID: s.Config.NodeID,
Node: s.Config.NodeName,
Partition: splitDefaultPartition,
Address: "127.0.0.1",
Datacenter: "dc1",
TaggedAddresses: map[string]string{
"lan": "127.0.0.1",
"lan_ipv4": "127.0.0.1",
"wan": "127.0.0.1",
"wan_ipv4": "127.0.0.1",
},
Meta: map[string]string{
"consul-network-segment": "",
},
}
require.Equal(r, want, nodes)
require.Equal(r, want, got)
})
}

Loading…
Cancel
Save