mirror of
https://github.com/libp2p/go-libp2p.git
synced 2025-10-05 16:17:12 +08:00
basichost: fix flaky TestSignedPeerRecordWithNoListenAddrs (#1488)
This commit is contained in:
@@ -92,29 +92,20 @@ func TestMultipleClose(t *testing.T) {
|
|||||||
func TestSignedPeerRecordWithNoListenAddrs(t *testing.T) {
|
func TestSignedPeerRecordWithNoListenAddrs(t *testing.T) {
|
||||||
h, err := NewHost(swarmt.GenSwarm(t, swarmt.OptDialOnly), nil)
|
h, err := NewHost(swarmt.GenSwarm(t, swarmt.OptDialOnly), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
defer h.Close()
|
||||||
h.Start()
|
h.Start()
|
||||||
|
|
||||||
if len(h.Addrs()) != 0 {
|
require.Empty(t, h.Addrs(), "expected no listen addrs")
|
||||||
t.Errorf("expected no listen addrs, got %d", len(h.Addrs()))
|
|
||||||
}
|
|
||||||
|
|
||||||
// now add a listen addr
|
// now add a listen addr
|
||||||
require.NoError(t, h.Network().Listen(ma.StringCast("/ip4/0.0.0.0/tcp/0")))
|
require.NoError(t, h.Network().Listen(ma.StringCast("/ip4/0.0.0.0/tcp/0")))
|
||||||
if len(h.Addrs()) < 1 {
|
require.NotEmpty(t, h.Addrs(), "expected at least 1 listen addr")
|
||||||
t.Errorf("expected at least 1 listen addr, got %d", len(h.Addrs()))
|
|
||||||
}
|
|
||||||
|
|
||||||
// we need to sleep for a moment, since the signed record with the new addr is
|
|
||||||
// added async
|
|
||||||
time.Sleep(20 * time.Millisecond)
|
|
||||||
|
|
||||||
cab, ok := peerstore.GetCertifiedAddrBook(h.Peerstore())
|
cab, ok := peerstore.GetCertifiedAddrBook(h.Peerstore())
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("peerstore doesn't support certified addrs")
|
t.Fatalf("peerstore doesn't support certified addrs")
|
||||||
}
|
}
|
||||||
if cab.GetPeerRecord(h.ID()) == nil {
|
// the signed record with the new addr is added async
|
||||||
t.Fatalf("no signed peer record in peerstore for new host %s", h.ID())
|
require.Eventually(t, func() bool { return cab.GetPeerRecord(h.ID()) != nil }, 100*time.Millisecond, 10*time.Millisecond)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProtocolHandlerEvents(t *testing.T) {
|
func TestProtocolHandlerEvents(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user