p2p/net/swarm: configurable timeout for tests
Juan Batiz-Benet committed
Jan 13, 2015 at 08:12 UTC
9689b280e696f8a42fd0d805d1e94e80717c4156
2 files changed
+6
-2
p2p/net/swarm/swarm.go
+4
@@ -4,6 +4,7 @@ package swarm
4
5
import (
6
"fmt"
7
+ "time"
8
9
inet "github.com/jbenet/go-ipfs/p2p/net"
10
addrutil "github.com/jbenet/go-ipfs/p2p/net/swarm/addr"
@@ -32,8 +33,10 @@ type Swarm struct {
33
local peer.ID
34
peers peer.Peerstore
35
connh ConnHandler
36
+
37
dsync dialsync
38
backf dialbackoff
39
+ dialT time.Duration // mainly for tests
40
41
cg ctxgroup.ContextGroup
42
}
@@ -55,6 +58,7 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
58
local: local,
59
peers: peers,
60
cg: ctxgroup.WithContext(ctx),
61
+ dialT: DialTimeout,
62
}
63
64
// configure Swarm
p2p/net/swarm/swarm_dial.go
+2
-2
@@ -210,7 +210,7 @@ func (s *Swarm) Dial(ctx context.Context, p peer.ID) (*Conn, error) {
210
// ok, we have been charged to dial! let's do it.
211
// if it succeeds, dial will add the conn to the swarm itself.
212
log.Debugf("dial start")
213
- ctxT, _ := context.WithTimeout(ctx, DialTimeout)
213
+ ctxT, _ := context.WithTimeout(ctx, s.dialT)
214
conn, err = s.dial(ctxT, p)
215
s.dsync.Unlock(p)
216
log.Debugf("dial end %s", conn)
@@ -264,7 +264,7 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) {
264
d := &conn.Dialer{
265
Dialer: manet.Dialer{
266
Dialer: net.Dialer{
267
- Timeout: DialTimeout,
267
+ Timeout: s.dialT,
268
},
269
},
270
LocalPeer: s.local,