Skip to content

Commit 3132878

Browse files
Backport of ci: fix TestNomad_BootstrapExpect_NonVoter test into release/1.3.x (#14409)
This pull request was automerged via backport-assistant
1 parent aa4c5d5 commit 3132878

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

nomad/serf_test.go

+26-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/hashicorp/nomad/testutil"
1313
"github.com/hashicorp/raft"
1414
"github.com/hashicorp/serf/serf"
15-
"github.com/hashicorp/serf/testutil/retry"
1615
"github.com/stretchr/testify/require"
1716
)
1817

@@ -328,16 +327,35 @@ func TestNomad_BootstrapExpect_NonVoter(t *testing.T) {
328327
})
329328
defer cleanupS4()
330329

330+
// Start with 4th server for higher chance of success when joining servers.
331+
servers := []*Server{s4, s3, s2, s1}
332+
331333
// Join with fourth server (now have quorum)
332-
// Start with 4th server for higher chance of success
333-
TestJoin(t, s4, s3, s2, s1)
334+
TestJoin(t, servers...)
334335

335336
// Assert leadership with 4 peers
336-
servers := []*Server{s1, s2, s3, s4}
337-
for _, s := range servers {
338-
testutil.WaitForLeader(t, s.RPC)
339-
retry.Run(t, func(r *retry.R) { r.Check(wantPeers(s, 4)) })
340-
}
337+
expect := len(servers)
338+
testutil.WaitForLeader(t, servers[0].RPC)
339+
testutil.WaitForResult(func() (bool, error) {
340+
// Retry the join to decrease flakiness
341+
TestJoin(t, servers...)
342+
for _, s := range servers {
343+
peers, err := s.numPeers()
344+
if err != nil {
345+
return false, fmt.Errorf("failed to get number of peers: %v", err)
346+
}
347+
if peers != expect {
348+
return false, fmt.Errorf("expected %d peers, got %d", expect, peers)
349+
}
350+
if len(s.localPeers) != expect {
351+
return false, fmt.Errorf("expected %d local peers, got %d: %#v", expect, len(s.localPeers), s.localPeers)
352+
}
353+
354+
}
355+
return true, nil
356+
}, func(err error) {
357+
require.NoError(t, err)
358+
})
341359
}
342360

343361
func TestNomad_BadExpect(t *testing.T) {

0 commit comments

Comments
 (0)