Commit 9d9e2a3b authored by Juan Batiz-Benet's avatar Juan Batiz-Benet
Browse files

p2p/net/swarm: configurable timeout for tests

parent 3d3ffc45
...@@ -4,6 +4,7 @@ package swarm ...@@ -4,6 +4,7 @@ package swarm
import ( import (
"fmt" "fmt"
"time"
inet "github.com/jbenet/go-ipfs/p2p/net" inet "github.com/jbenet/go-ipfs/p2p/net"
addrutil "github.com/jbenet/go-ipfs/p2p/net/swarm/addr" addrutil "github.com/jbenet/go-ipfs/p2p/net/swarm/addr"
...@@ -32,8 +33,10 @@ type Swarm struct { ...@@ -32,8 +33,10 @@ type Swarm struct {
local peer.ID local peer.ID
peers peer.Peerstore peers peer.Peerstore
connh ConnHandler connh ConnHandler
dsync dialsync dsync dialsync
backf dialbackoff backf dialbackoff
dialT time.Duration // mainly for tests
cg ctxgroup.ContextGroup cg ctxgroup.ContextGroup
} }
...@@ -55,6 +58,7 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr, ...@@ -55,6 +58,7 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
local: local, local: local,
peers: peers, peers: peers,
cg: ctxgroup.WithContext(ctx), cg: ctxgroup.WithContext(ctx),
dialT: DialTimeout,
} }
// configure Swarm // configure Swarm
......
...@@ -210,7 +210,7 @@ func (s *Swarm) Dial(ctx context.Context, p peer.ID) (*Conn, error) { ...@@ -210,7 +210,7 @@ func (s *Swarm) Dial(ctx context.Context, p peer.ID) (*Conn, error) {
// ok, we have been charged to dial! let's do it. // ok, we have been charged to dial! let's do it.
// if it succeeds, dial will add the conn to the swarm itself. // if it succeeds, dial will add the conn to the swarm itself.
log.Debugf("dial start") log.Debugf("dial start")
ctxT, _ := context.WithTimeout(ctx, DialTimeout) ctxT, _ := context.WithTimeout(ctx, s.dialT)
conn, err = s.dial(ctxT, p) conn, err = s.dial(ctxT, p)
s.dsync.Unlock(p) s.dsync.Unlock(p)
log.Debugf("dial end %s", conn) log.Debugf("dial end %s", conn)
...@@ -264,7 +264,7 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) { ...@@ -264,7 +264,7 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) {
d := &conn.Dialer{ d := &conn.Dialer{
Dialer: manet.Dialer{ Dialer: manet.Dialer{
Dialer: net.Dialer{ Dialer: net.Dialer{
Timeout: DialTimeout, Timeout: s.dialT,
}, },
}, },
LocalPeer: s.local, LocalPeer: s.local,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment