Skip to content

Commit

Permalink
add extra resiliency to snapshot restore test (#16712)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhiaayachi authored Mar 21, 2023
1 parent 8f7e4d4 commit 769d950
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -79,13 +80,27 @@ 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)

// 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})
Expand Down

0 comments on commit 769d950

Please sign in to comment.