fix p2p discovery test issue

pull/4351/head
“GheisMohammadi” 2 years ago committed by Casey Gardiner
parent fecd4fdda3
commit e49dfd7824
  1. 10
      p2p/discovery/discovery_test.go
  2. 6
      p2p/discovery/option_test.go
  3. 2
      p2p/stream/common/streammanager/streammanager.go

@ -3,9 +3,11 @@ package discovery
// TODO: test this module
import (
"context"
"testing"
"github.com/libp2p/go-libp2p"
dht "github.com/libp2p/go-libp2p-kad-dht"
)
func TestNewDHTDiscovery(t *testing.T) {
@ -13,7 +15,13 @@ func TestNewDHTDiscovery(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, err = NewDHTDiscovery(host, DHTConfig{})
ctx, cancel := context.WithCancel(context.Background())
var idht *dht.IpfsDHT
idht, err = dht.New(ctx, host)
if err != nil {
t.Fatal(err)
}
_, err = NewDHTDiscovery(ctx, cancel, host, idht, DHTConfig{})
if err != nil {
t.Fatal(err)
}

@ -40,14 +40,14 @@ func TestDHTOption_getLibp2pRawOptions(t *testing.T) {
opt: DHTConfig{
BootNodes: testAddrStr,
},
expLen: 1,
expLen: 2,
},
{
opt: DHTConfig{
BootNodes: testAddrStr,
DataStoreFile: &validPath,
},
expLen: 2,
expLen: 3,
},
{
opt: DHTConfig{
@ -58,7 +58,7 @@ func TestDHTOption_getLibp2pRawOptions(t *testing.T) {
},
}
for i, test := range tests {
opts, err := test.opt.getLibp2pRawOptions()
opts, err := test.opt.GetLibp2pRawOptions()
if assErr := assertError(err, test.expErr); assErr != nil {
t.Errorf("Test %v: %v", i, assErr)
}

@ -323,7 +323,7 @@ func (sm *streamManager) discoverAndSetupStream(discCtx context.Context) (int, e
// The ctx here is using the module context instead of discover context
err := sm.setupStreamWithPeer(sm.ctx, pid)
if err != nil {
sm.coolDownCache.Add(peer.ID)
sm.coolDownCache.Add(pid)
sm.logger.Warn().Err(err).Str("peerID", string(pid)).Msg("failed to setup stream with peer")
return
}

Loading…
Cancel
Save