Merge pull request #11236 from hashicorp/test-flaky-autopilot
test: fix flaky TestAutopilot_CleanupDeadServer
This commit is contained in:
commit
24134a047a
|
@ -68,11 +68,8 @@ func wantRaft(servers []*Server) error {
|
|||
|
||||
func TestAutopilot_CleanupDeadServer(t *testing.T) {
|
||||
t.Parallel()
|
||||
for i := 1; i <= 3; i++ {
|
||||
t.Run(fmt.Sprintf("raft version: %v", i), func(t *testing.T) {
|
||||
testCleanupDeadServer(t, i)
|
||||
})
|
||||
}
|
||||
t.Run("raft_v2", func(t *testing.T) { testCleanupDeadServer(t, 2) })
|
||||
t.Run("raft_v3", func(t *testing.T) { testCleanupDeadServer(t, 3) })
|
||||
}
|
||||
|
||||
func testCleanupDeadServer(t *testing.T, raftVersion int) {
|
||||
|
@ -93,9 +90,10 @@ func testCleanupDeadServer(t *testing.T, raftVersion int) {
|
|||
servers := []*Server{s1, s2, s3}
|
||||
|
||||
// Try to join
|
||||
TestJoin(t, s1, s2, s3)
|
||||
TestJoin(t, servers...)
|
||||
|
||||
for _, s := range servers {
|
||||
testutil.WaitForLeader(t, s.RPC)
|
||||
retry.Run(t, func(r *retry.R) { r.Check(wantPeers(s, 3)) })
|
||||
}
|
||||
|
||||
|
@ -104,26 +102,37 @@ func testCleanupDeadServer(t *testing.T, raftVersion int) {
|
|||
defer cleanupS4()
|
||||
|
||||
// Kill a non-leader server
|
||||
if leader := waitForStableLeadership(t, servers); leader == s3 {
|
||||
s3, s1 = s1, s3
|
||||
killedIdx := 0
|
||||
for i, s := range servers {
|
||||
if !s.IsLeader() {
|
||||
killedIdx = i
|
||||
s.Shutdown()
|
||||
break
|
||||
}
|
||||
}
|
||||
s3.Shutdown()
|
||||
|
||||
retry.Run(t, func(r *retry.R) {
|
||||
alive := 0
|
||||
for _, m := range s1.Members() {
|
||||
if m.Status == serf.StatusAlive {
|
||||
alive++
|
||||
for i, s := range servers {
|
||||
alive := 0
|
||||
if i == killedIdx {
|
||||
// Skip shutdown server
|
||||
continue
|
||||
}
|
||||
for _, m := range s.Members() {
|
||||
if m.Status == serf.StatusAlive {
|
||||
alive++
|
||||
}
|
||||
}
|
||||
|
||||
if alive != 2 {
|
||||
r.Fatalf("expected 2 alive servers but found %v", alive)
|
||||
}
|
||||
}
|
||||
if alive != 2 {
|
||||
r.Fatalf("expected 2 alive servers but found %v", alive)
|
||||
}
|
||||
})
|
||||
|
||||
// Join the new server
|
||||
TestJoin(t, s1, s2, s4)
|
||||
servers[2] = s4
|
||||
servers[killedIdx] = s4
|
||||
TestJoin(t, servers...)
|
||||
|
||||
waitForStableLeadership(t, servers)
|
||||
|
||||
|
|
Loading…
Reference in a new issue