Skip to content

Commit

Permalink
fix: unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
istae committed Oct 20, 2023
1 parent 5ae0e7b commit 4a3db58
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/topology/kademlia/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,7 @@ func closestPeer(peers *pslice.PSlice, addr swarm.Address) (swarm.Address, error

return closest, nil
}

func (k *Kad) Trigger() {
k.manageC <- struct{}{}
}
1 change: 1 addition & 0 deletions pkg/topology/kademlia/kademlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ func (k *Kad) manage() {
}
}()

// tell each neighbor about other neighbors periodically
k.wg.Add(1)
go func() {
defer k.wg.Done()
Expand Down
8 changes: 6 additions & 2 deletions pkg/topology/kademlia/kademlia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,11 +811,11 @@ func TestAddressBookPrune(t *testing.T) {
var (
conns, failedConns int32 // how many connect calls were made to the p2p mock
base, kad, ab, _, signer = newTestKademlia(t, &conns, &failedConns, kademlia.Options{
TimeToRetry: ptrDuration(20 * time.Millisecond),
TimeToRetry: ptrDuration(0),
})
)

kad.SetStorageRadius(2)
kad.SetStorageRadius(0)

if err := kad.Start(context.Background()); err != nil {
t.Fatal(err)
Expand All @@ -834,6 +834,10 @@ func TestAddressBookPrune(t *testing.T) {
kad.AddPeers(nonConnPeer.Overlay)
waitCounter(t, &conns, 0)
waitCounter(t, &failedConns, 1)
kad.Trigger()
waitCounter(t, &failedConns, 1)
kad.Trigger()
waitCounter(t, &failedConns, 1)

_, err = ab.Get(nonConnPeer.Overlay)
if !errors.Is(err, addressbook.ErrNotFound) {
Expand Down

0 comments on commit 4a3db58

Please sign in to comment.