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 // TODO: test this module
import ( import (
"context"
"testing" "testing"
"github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p"
dht "github.com/libp2p/go-libp2p-kad-dht"
) )
func TestNewDHTDiscovery(t *testing.T) { func TestNewDHTDiscovery(t *testing.T) {
@ -13,7 +15,13 @@ func TestNewDHTDiscovery(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

@ -40,14 +40,14 @@ func TestDHTOption_getLibp2pRawOptions(t *testing.T) {
opt: DHTConfig{ opt: DHTConfig{
BootNodes: testAddrStr, BootNodes: testAddrStr,
}, },
expLen: 1, expLen: 2,
}, },
{ {
opt: DHTConfig{ opt: DHTConfig{
BootNodes: testAddrStr, BootNodes: testAddrStr,
DataStoreFile: &validPath, DataStoreFile: &validPath,
}, },
expLen: 2, expLen: 3,
}, },
{ {
opt: DHTConfig{ opt: DHTConfig{
@ -58,7 +58,7 @@ func TestDHTOption_getLibp2pRawOptions(t *testing.T) {
}, },
} }
for i, test := range tests { for i, test := range tests {
opts, err := test.opt.getLibp2pRawOptions() opts, err := test.opt.GetLibp2pRawOptions()
if assErr := assertError(err, test.expErr); assErr != nil { if assErr := assertError(err, test.expErr); assErr != nil {
t.Errorf("Test %v: %v", i, assErr) 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 // The ctx here is using the module context instead of discover context
err := sm.setupStreamWithPeer(sm.ctx, pid) err := sm.setupStreamWithPeer(sm.ctx, pid)
if err != nil { 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") sm.logger.Warn().Err(err).Str("peerID", string(pid)).Msg("failed to setup stream with peer")
return return
} }

Loading…
Cancel
Save