Skip to content

Commit

Permalink
add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed May 17, 2022
1 parent 928bc0c commit 95d74b5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions p2p/net/swarm/dial_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package swarm

import (
"context"
"fmt"
"sync"

"github.com/libp2p/go-libp2p-core/network"
Expand Down Expand Up @@ -80,6 +81,7 @@ func (ds *dialSync) getActiveDial(p peer.ID) (*activeDial, error) {
cancel: cancel,
reqch: make(chan dialRequest),
}
fmt.Println("creating new active dial")
go ds.dialWorker(p, actd.reqch)
ds.dials[p] = actd
}
Expand All @@ -102,6 +104,7 @@ func (ds *dialSync) Dial(ctx context.Context, p peer.ID) (*Conn, error) {
ad.refCnt--
if ad.refCnt == 0 {
ad.close()
fmt.Println("deleting dial")
delete(ds.dials, p)
}
}()
Expand Down
5 changes: 3 additions & 2 deletions p2p/net/swarm/dial_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestBasicDialSync(t *testing.T) {
requests := make(chan dialRequest, 2)
done := make(chan struct{})
dsync := newDialSync(func(id peer.ID, reqs <-chan dialRequest) {
fmt.Println("dialWorkerFunc")
require.Equal(t, id, p)
atomic.AddInt32(&counter, 1)
for req := range reqs {
Expand Down Expand Up @@ -65,11 +66,11 @@ func TestBasicDialSync(t *testing.T) {
}()

// wait until both requests are registered
require.Eventually(t, func() bool { return len(requests) == 2 }, 100*time.Millisecond, 5*time.Millisecond, "expected both requests to be processed")
require.Eventually(t, func() bool { return len(requests) == 2 }, 1000*time.Millisecond, 5*time.Millisecond, "expected both requests to be processed")
// make the dials return
close(done)
// make sure the Dial functions return
require.Eventually(t, func() bool { return len(finished) == 2 }, 100*time.Millisecond, 5*time.Millisecond, "dial functions should have returned")
require.Eventually(t, func() bool { return len(finished) == 2 }, 1000*time.Millisecond, 5*time.Millisecond, "dial functions should have returned")

require.Equal(t, 1, int(atomic.LoadInt32(&counter)), "should only have called dial func once!")
}
Expand Down

0 comments on commit 95d74b5

Please sign in to comment.