@@ -14,7 +14,6 @@ import (
14
14
"github.com/libp2p/go-libp2p-core/peer"
15
15
"github.com/libp2p/go-libp2p-core/peerstore"
16
16
testutil "github.com/libp2p/go-libp2p-core/test"
17
- "github.com/libp2p/go-libp2p-core/transport"
18
17
swarmt "github.com/libp2p/go-libp2p-swarm/testing"
19
18
"github.com/libp2p/go-libp2p-testing/ci"
20
19
@@ -24,10 +23,6 @@ import (
24
23
"github.com/stretchr/testify/require"
25
24
)
26
25
27
- func init () {
28
- transport .DialTimeout = time .Second
29
- }
30
-
31
26
func closeSwarms (swarms []* Swarm ) {
32
27
for _ , s := range swarms {
33
28
s .Close ()
@@ -161,8 +156,9 @@ func newSilentPeer(t *testing.T) (peer.ID, ma.Multiaddr, net.Listener) {
161
156
func TestDialWait (t * testing.T ) {
162
157
t .Parallel ()
163
158
164
- ctx := context .Background ()
165
- swarms := makeSwarms (t , 1 )
159
+ const dialTimeout = 250 * time .Millisecond
160
+
161
+ swarms := makeSwarms (t , 1 , swarmt .DialTimeout (dialTimeout ))
166
162
s1 := swarms [0 ]
167
163
defer s1 .Close ()
168
164
@@ -173,19 +169,19 @@ func TestDialWait(t *testing.T) {
173
169
s1 .Peerstore ().AddAddr (s2p , s2addr , peerstore .PermanentAddrTTL )
174
170
175
171
before := time .Now ()
176
- if c , err := s1 .DialPeer (ctx , s2p ); err == nil {
172
+ if c , err := s1 .DialPeer (context . Background () , s2p ); err == nil {
177
173
defer c .Close ()
178
174
t .Fatal ("error swarm dialing to unknown peer worked..." , err )
179
175
} else {
180
176
t .Log ("correctly got error:" , err )
181
177
}
182
178
duration := time .Since (before )
183
179
184
- if duration < transport . DialTimeout * DialAttempts {
185
- t .Error ("< transport.DialTimeout * DialAttempts not being respected" , duration , transport . DialTimeout * DialAttempts )
180
+ if duration < dialTimeout * DialAttempts {
181
+ t .Error ("< dialTimeout * DialAttempts not being respected" , duration , dialTimeout * DialAttempts )
186
182
}
187
- if duration > 2 * transport . DialTimeout * DialAttempts {
188
- t .Error ("> 2*transport.DialTimeout * DialAttempts not being respected" , duration , 2 * transport . DialTimeout * DialAttempts )
183
+ if duration > 2 * dialTimeout * DialAttempts {
184
+ t .Error ("> 2*dialTimeout * DialAttempts not being respected" , duration , 2 * dialTimeout * DialAttempts )
189
185
}
190
186
191
187
if ! s1 .Backoff ().Backoff (s2p , s2addr ) {
@@ -194,15 +190,16 @@ func TestDialWait(t *testing.T) {
194
190
}
195
191
196
192
func TestDialBackoff (t * testing.T ) {
197
- // t.Skip("skipping for another test")
198
193
if ci .IsRunning () {
199
194
t .Skip ("travis will never have fun with this test" )
200
195
}
201
196
202
197
t .Parallel ()
203
198
199
+ const dialTimeout = 250 * time .Millisecond
200
+
204
201
ctx := context .Background ()
205
- swarms := makeSwarms (t , 2 )
202
+ swarms := makeSwarms (t , 2 , swarmt . DialTimeout ( dialTimeout ) )
206
203
s1 := swarms [0 ]
207
204
s2 := swarms [1 ]
208
205
defer s1 .Close ()
@@ -269,8 +266,8 @@ func TestDialBackoff(t *testing.T) {
269
266
s3done := dialOfflineNode (s3p , N )
270
267
271
268
// when all dials should be done by:
272
- dialTimeout1x := time .After (transport . DialTimeout )
273
- dialTimeout10Ax := time .After (transport . DialTimeout * 2 * 10 ) // DialAttempts * 10)
269
+ dialTimeout1x := time .After (dialTimeout )
270
+ dialTimeout10Ax := time .After (dialTimeout * 2 * 10 ) // DialAttempts * 10)
274
271
275
272
// 2) all dials should hang
276
273
select {
@@ -352,8 +349,8 @@ func TestDialBackoff(t *testing.T) {
352
349
s3done := dialOfflineNode (s3p , N )
353
350
354
351
// when all dials should be done by:
355
- dialTimeout1x := time .After (transport . DialTimeout )
356
- dialTimeout10Ax := time .After (transport . DialTimeout * 2 * 10 ) // DialAttempts * 10)
352
+ dialTimeout1x := time .After (dialTimeout )
353
+ dialTimeout10Ax := time .After (dialTimeout * 2 * 10 ) // DialAttempts * 10)
357
354
358
355
// 7) s3 dials should all return immediately (except 1)
359
356
for i := 0 ; i < N - 1 ; i ++ {
@@ -405,11 +402,12 @@ func TestDialBackoff(t *testing.T) {
405
402
}
406
403
407
404
func TestDialBackoffClears (t * testing.T ) {
408
- // t.Skip("skipping for another test")
409
405
t .Parallel ()
410
406
407
+ const dialTimeout = 250 * time .Millisecond
408
+
411
409
ctx := context .Background ()
412
- swarms := makeSwarms (t , 2 )
410
+ swarms := makeSwarms (t , 2 , swarmt . DialTimeout ( dialTimeout ) )
413
411
s1 := swarms [0 ]
414
412
s2 := swarms [1 ]
415
413
defer s1 .Close ()
@@ -433,11 +431,11 @@ func TestDialBackoffClears(t *testing.T) {
433
431
}
434
432
duration := time .Since (before )
435
433
436
- if duration < transport . DialTimeout * DialAttempts {
437
- t .Error ("< transport.DialTimeout * DialAttempts not being respected" , duration , transport . DialTimeout * DialAttempts )
434
+ if duration < dialTimeout * DialAttempts {
435
+ t .Error ("< dialTimeout * DialAttempts not being respected" , duration , dialTimeout * DialAttempts )
438
436
}
439
- if duration > 2 * transport . DialTimeout * DialAttempts {
440
- t .Error ("> 2*transport.DialTimeout * DialAttempts not being respected" , duration , 2 * transport . DialTimeout * DialAttempts )
437
+ if duration > 2 * dialTimeout * DialAttempts {
438
+ t .Error ("> 2*dialTimeout * DialAttempts not being respected" , duration , 2 * dialTimeout * DialAttempts )
441
439
}
442
440
443
441
if ! s1 .Backoff ().Backoff (s2 .LocalPeer (), s2bad ) {
@@ -561,7 +559,9 @@ func TestDialSimultaneousJoin(t *testing.T) {
561
559
ctx , cancel := context .WithCancel (context .Background ())
562
560
defer cancel ()
563
561
564
- swarms := makeSwarms (t , 2 )
562
+ const dialTimeout = 250 * time .Millisecond
563
+
564
+ swarms := makeSwarms (t , 2 , swarmt .DialTimeout (dialTimeout ))
565
565
s1 := swarms [0 ]
566
566
s2 := swarms [1 ]
567
567
defer s1 .Close ()
@@ -654,7 +654,7 @@ func TestDialSimultaneousJoin(t *testing.T) {
654
654
if c1 != c2 {
655
655
t .Fatal ("expected c1 and c2 to be the same" )
656
656
}
657
- case <- time .After (2 * transport . DialTimeout ):
657
+ case <- time .After (2 * dialTimeout ):
658
658
t .Fatal ("no connection from first dial" )
659
659
}
660
660
}
0 commit comments