Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(share/discovery): fix TestDiscovery test #3699

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading