From 9689b280e696f8a42fd0d805d1e94e80717c4156 Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Tue, 13 Jan 2015 08:12:45 -0800 Subject: [PATCH] p2p/net/swarm: configurable timeout for tests --- p2p/net/swarm/swarm.go | 4 ++++ p2p/net/swarm/swarm_dial.go | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/p2p/net/swarm/swarm.go b/p2p/net/swarm/swarm.go index f78984a08..5e3c667eb 100644 --- a/p2p/net/swarm/swarm.go +++ b/p2p/net/swarm/swarm.go @@ -4,6 +4,7 @@ package swarm import ( "fmt" + "time" inet "github.com/jbenet/go-ipfs/p2p/net" addrutil "github.com/jbenet/go-ipfs/p2p/net/swarm/addr" @@ -32,8 +33,10 @@ type Swarm struct { local peer.ID peers peer.Peerstore connh ConnHandler + dsync dialsync backf dialbackoff + dialT time.Duration // mainly for tests cg ctxgroup.ContextGroup } @@ -55,6 +58,7 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr, local: local, peers: peers, cg: ctxgroup.WithContext(ctx), + dialT: DialTimeout, } // configure Swarm diff --git a/p2p/net/swarm/swarm_dial.go b/p2p/net/swarm/swarm_dial.go index 5b1569856..efb3c040e 100644 --- a/p2p/net/swarm/swarm_dial.go +++ b/p2p/net/swarm/swarm_dial.go @@ -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. // if it succeeds, dial will add the conn to the swarm itself. log.Debugf("dial start") - ctxT, _ := context.WithTimeout(ctx, DialTimeout) + ctxT, _ := context.WithTimeout(ctx, s.dialT) conn, err = s.dial(ctxT, p) s.dsync.Unlock(p) log.Debugf("dial end %s", conn) @@ -264,7 +264,7 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) { d := &conn.Dialer{ Dialer: manet.Dialer{ Dialer: net.Dialer{ - Timeout: DialTimeout, + Timeout: s.dialT, }, }, LocalPeer: s.local,