@@ -15,7 +15,7 @@ func getMockDialFunc() (dialWorkerFunc, func(), context.Context, <-chan struct{}
15
15
dfcalls := make (chan struct {}, 512 ) // buffer it large enough that we won't care
16
16
dialctx , cancel := context .WithCancel (context .Background ())
17
17
ch := make (chan struct {})
18
- f := func (p peer.ID , reqch <- chan dialRequest ) error {
18
+ f := func (p peer.ID , reqch <- chan dialRequest ) {
19
19
defer cancel ()
20
20
dfcalls <- struct {}{}
21
21
go func () {
@@ -24,7 +24,6 @@ func getMockDialFunc() (dialWorkerFunc, func(), context.Context, <-chan struct{}
24
24
req .resch <- dialResponse {conn : new (Conn )}
25
25
}
26
26
}()
27
- return nil
28
27
}
29
28
30
29
var once sync.Once
@@ -38,14 +37,14 @@ func TestBasicDialSync(t *testing.T) {
38
37
39
38
finished := make (chan struct {}, 2 )
40
39
go func () {
41
- if _ , err := dsync .DialLock (context .Background (), p ); err != nil {
40
+ if _ , err := dsync .Dial (context .Background (), p ); err != nil {
42
41
t .Error (err )
43
42
}
44
43
finished <- struct {}{}
45
44
}()
46
45
47
46
go func () {
48
- if _ , err := dsync .DialLock (context .Background (), p ); err != nil {
47
+ if _ , err := dsync .Dial (context .Background (), p ); err != nil {
49
48
t .Error (err )
50
49
}
51
50
finished <- struct {}{}
@@ -74,7 +73,7 @@ func TestDialSyncCancel(t *testing.T) {
74
73
75
74
finished := make (chan struct {})
76
75
go func () {
77
- _ , err := dsync .DialLock (ctx1 , p )
76
+ _ , err := dsync .Dial (ctx1 , p )
78
77
if err != ctx1 .Err () {
79
78
t .Error ("should have gotten context error" )
80
79
}
@@ -90,7 +89,7 @@ func TestDialSyncCancel(t *testing.T) {
90
89
91
90
// Add a second dialwait in so two actors are waiting on the same dial
92
91
go func () {
93
- _ , err := dsync .DialLock (context .Background (), p )
92
+ _ , err := dsync .Dial (context .Background (), p )
94
93
if err != nil {
95
94
t .Error (err )
96
95
}
@@ -123,15 +122,15 @@ func TestDialSyncAllCancel(t *testing.T) {
123
122
124
123
finished := make (chan struct {})
125
124
go func () {
126
- if _ , err := dsync .DialLock (ctx , p ); err != ctx .Err () {
125
+ if _ , err := dsync .Dial (ctx , p ); err != ctx .Err () {
127
126
t .Error ("should have gotten context error" )
128
127
}
129
128
finished <- struct {}{}
130
129
}()
131
130
132
131
// Add a second dialwait in so two actors are waiting on the same dial
133
132
go func () {
134
- if _ , err := dsync .DialLock (ctx , p ); err != ctx .Err () {
133
+ if _ , err := dsync .Dial (ctx , p ); err != ctx .Err () {
135
134
t .Error ("should have gotten context error" )
136
135
}
137
136
finished <- struct {}{}
@@ -155,14 +154,14 @@ func TestDialSyncAllCancel(t *testing.T) {
155
154
156
155
// should be able to successfully dial that peer again
157
156
done ()
158
- if _ , err := dsync .DialLock (context .Background (), p ); err != nil {
157
+ if _ , err := dsync .Dial (context .Background (), p ); err != nil {
159
158
t .Fatal (err )
160
159
}
161
160
}
162
161
163
162
func TestFailFirst (t * testing.T ) {
164
163
var count int32
165
- f := func (p peer.ID , reqch <- chan dialRequest ) error {
164
+ f := func (p peer.ID , reqch <- chan dialRequest ) {
166
165
go func () {
167
166
for {
168
167
req , ok := <- reqch
@@ -178,33 +177,29 @@ func TestFailFirst(t *testing.T) {
178
177
atomic .AddInt32 (& count , 1 )
179
178
}
180
179
}()
181
- return nil
182
180
}
183
181
184
182
ds := newDialSync (f )
185
-
186
183
p := peer .ID ("testing" )
187
184
188
185
ctx , cancel := context .WithTimeout (context .Background (), time .Second * 5 )
189
186
defer cancel ()
190
187
191
- _ , err := ds .DialLock (ctx , p )
192
- if err == nil {
188
+ if _ , err := ds .Dial (ctx , p ); err == nil {
193
189
t .Fatal ("expected gophers to have eaten the modem" )
194
190
}
195
191
196
- c , err := ds .DialLock (ctx , p )
192
+ c , err := ds .Dial (ctx , p )
197
193
if err != nil {
198
194
t .Fatal (err )
199
195
}
200
-
201
196
if c == nil {
202
197
t .Fatal ("should have gotten a 'real' conn back" )
203
198
}
204
199
}
205
200
206
201
func TestStressActiveDial (t * testing.T ) {
207
- ds := newDialSync (func (p peer.ID , reqch <- chan dialRequest ) error {
202
+ ds := newDialSync (func (p peer.ID , reqch <- chan dialRequest ) {
208
203
go func () {
209
204
for {
210
205
req , ok := <- reqch
@@ -214,7 +209,6 @@ func TestStressActiveDial(t *testing.T) {
214
209
req .resch <- dialResponse {}
215
210
}
216
211
}()
217
- return nil
218
212
})
219
213
220
214
wg := sync.WaitGroup {}
@@ -223,7 +217,7 @@ func TestStressActiveDial(t *testing.T) {
223
217
224
218
makeDials := func () {
225
219
for i := 0 ; i < 10000 ; i ++ {
226
- ds .DialLock (context .Background (), pid )
220
+ ds .Dial (context .Background (), pid )
227
221
}
228
222
wg .Done ()
229
223
}
@@ -235,24 +229,3 @@ func TestStressActiveDial(t *testing.T) {
235
229
236
230
wg .Wait ()
237
231
}
238
-
239
- func TestDialSelf (t * testing.T ) {
240
- ctx , cancel := context .WithCancel (context .Background ())
241
- defer cancel ()
242
-
243
- self := peer .ID ("ABC" )
244
- s := NewSwarm (ctx , self , nil , nil )
245
- defer s .Close ()
246
-
247
- // this should fail
248
- _ , err := s .dsync .DialLock (ctx , self )
249
- if err != ErrDialToSelf {
250
- t .Fatal ("expected error from self dial" )
251
- }
252
-
253
- // do it twice to make sure we get a new active dial object that fails again
254
- _ , err = s .dsync .DialLock (ctx , self )
255
- if err != ErrDialToSelf {
256
- t .Fatal ("expected error from self dial" )
257
- }
258
- }
0 commit comments