From 769d9505a8bdefb938128adea370b4384feb18f6 Mon Sep 17 00:00:00 2001 From: Dhia Ayachi Date: Tue, 21 Mar 2023 14:27:00 -0400 Subject: [PATCH] add extra resiliency to snapshot restore test (#16712) --- .../test/snapshot/snapshot_restore_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/integration/consul-container/test/snapshot/snapshot_restore_test.go b/test/integration/consul-container/test/snapshot/snapshot_restore_test.go index 1d82b1cfb1..35621ab99b 100644 --- a/test/integration/consul-container/test/snapshot/snapshot_restore_test.go +++ b/test/integration/consul-container/test/snapshot/snapshot_restore_test.go @@ -3,6 +3,7 @@ package snapshot import ( "fmt" "github.com/hashicorp/consul/api" + "github.com/hashicorp/consul/sdk/testutil/retry" libcluster "github.com/hashicorp/consul/test/integration/consul-container/libs/cluster" libtopology "github.com/hashicorp/consul/test/integration/consul-container/libs/topology" "github.com/hashicorp/consul/test/integration/consul-container/libs/utils" @@ -79,6 +80,9 @@ func testSnapShotRestoreForLogStore(t *testing.T, logStore libcluster.LogStore) libcluster.WaitForLeader(t, cluster2, client2) + leader, err := cluster2.Leader() + require.NoError(t, err) + followers, err := cluster2.Followers() require.NoError(t, err) require.Len(t, followers, 2) @@ -86,6 +90,17 @@ func testSnapShotRestoreForLogStore(t *testing.T, logStore libcluster.LogStore) // use a follower api client and set `AllowStale` to true // to test the follower snapshot install code path as well. fc := followers[0].GetClient() + lc := leader.GetClient() + + retry.Run(t, func(r *retry.R) { + self, err := lc.Agent().Self() + require.NoError(r, err) + LeaderLogIndex := self["Stats"]["raft"].(map[string]interface{})["last_log_index"].(string) + self, err = fc.Agent().Self() + require.NoError(r, err) + followerLogIndex := self["Stats"]["raft"].(map[string]interface{})["last_log_index"].(string) + require.Equal(r, LeaderLogIndex, followerLogIndex) + }) for i := 0; i < 100; i++ { kv, _, err := fc.KV().Get(fmt.Sprintf("key-%d", i), &api.QueryOptions{AllowStale: true})