Skip to content

Commit

Permalink
fix(share/discovery): fix TestDiscovery test (#3699)
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss authored Aug 29, 2024
1 parent 50b0a57 commit afd8667
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions share/p2p/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestDiscovery(t *testing.T) {

discoveryRetryTimeout = time.Millisecond * 100 // defined in discovery.go

ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*40)
t.Cleanup(cancel)

tn := newTestnet(ctx, t)
Expand All @@ -50,21 +50,23 @@ func TestDiscovery(t *testing.T) {
peerA := tn.startNewDiscovery(params, host, routingDisc, fullNodesTag,
WithOnPeersUpdate(submit),
)

// start discovery advertisement services for other peers
params.AdvertiseInterval = time.Millisecond * 100
discs := make([]*Discovery, nodes)
for i := range discs {
// start discovery advertisement services for other peers
discs := make(map[string]*Discovery, nodes)
for range nodes {
host, routingDisc := tn.peer()
disc, err := NewDiscovery(params, host, routingDisc, fullNodesTag)
require.NoError(t, err)
go disc.Advertise(tn.ctx)
discs[i] = tn.startNewDiscovery(params, host, routingDisc, fullNodesTag)
disc := tn.startNewDiscovery(params, host, routingDisc, fullNodesTag, WithAdvertise())
discs[disc.host.ID().String()] = disc
}

for range nodes {
select {
case res := <-updateCh:
require.Equal(t, discs[i].host.ID(), res.peerID)
require.True(t, res.isAdded)
if _, ok := discs[res.peerID.String()]; !ok {
t.Fatal("discovered unknown peer")
}
delete(discs, res.peerID.String())
case <-ctx.Done():
t.Fatal("did not discover peer in time")
}
Expand All @@ -87,7 +89,7 @@ func TestDiscovery(t *testing.T) {
}
}

assert.EqualValues(t, 0, peerA.set.Size())
assert.Equal(t, uint(10), peerA.set.Size())
}

func TestDiscoveryTagged(t *testing.T) {
Expand Down Expand Up @@ -190,8 +192,6 @@ func (t *testnet) peer() (host.Host, discovery.Discovery) {
dht, err := dht.New(t.ctx, hst,
dht.Mode(dht.ModeServer),
dht.ProtocolPrefix("/test"),
// needed to reduce connections to peers on DHT level
dht.BucketSize(1),
)
require.NoError(t.T, err)

Expand Down

0 comments on commit afd8667

Please sign in to comment.