Skip to content

Commit 118cfbd

Browse files
author
tac0turtle
committed
attempt to fix flakiness
1 parent a129efc commit 118cfbd

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

pkg/p2p/client_test.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,34 @@ func TestClientInfoMethods(t *testing.T) {
341341
})
342342

343343
t.Run("GetPeers", func(t *testing.T) {
344+
// Wait for peer discovery to find the peers
345+
expectedPeerIDs := []peer.ID{client1.host.ID(), client2.host.ID()}
346+
347+
err := waitForCondition(2*time.Second, func() bool {
348+
peers, err := client0.GetPeers()
349+
if err != nil {
350+
return false
351+
}
352+
353+
actualPeerIDs := make(map[peer.ID]bool)
354+
for _, p := range peers {
355+
actualPeerIDs[p.ID] = true
356+
}
357+
358+
// Check if all expected peers are found
359+
for _, expectedID := range expectedPeerIDs {
360+
if !actualPeerIDs[expectedID] {
361+
return false
362+
}
363+
}
364+
return true
365+
})
366+
367+
require.NoError(err, "Timed out waiting for GetPeers to discover all peers")
368+
369+
// Now verify the peers are as expected
344370
peers, err := client0.GetPeers()
345371
assert.NoError(err)
346-
expectedPeerIDs := []peer.ID{client1.host.ID(), client2.host.ID()}
347372
actualPeerIDs := make([]peer.ID, len(peers))
348373
for i, p := range peers {
349374
actualPeerIDs[i] = p.ID

0 commit comments

Comments
 (0)