@@ -55,7 +55,6 @@ module.exports = (common) => {
55
55
return callback ( err )
56
56
}
57
57
58
- console . log ( '->' , peers )
59
58
const hasAllPeers = peersToWait
60
59
. map ( ( e ) => peers . includes ( e ) )
61
60
. filter ( ( e ) => e === false )
@@ -134,6 +133,18 @@ module.exports = (common) => {
134
133
} )
135
134
136
135
describe ( '.peers' , ( ) => {
136
+ before ( ( done ) => {
137
+ ipfs2 . id ( ( err , id ) => {
138
+ expect ( err ) . to . not . exist
139
+ const ipfs2Addr = id . addresses [ 0 ]
140
+ ipfs1 . swarm . connect ( ipfs2Addr , ( err ) => {
141
+ expect ( err ) . to . not . exist
142
+ // We need to fix this on libp2p level
143
+ setTimeout ( done , 3000 )
144
+ } )
145
+ } )
146
+ } )
147
+
137
148
// TODO clarify what is the goal of pubsub.peers
138
149
it ( 'returns an error when not subscribed to a topic' , ( done ) => {
139
150
ipfs1 . pubsub . peers ( topic , ( err , peers ) => {
@@ -143,7 +154,7 @@ module.exports = (common) => {
143
154
} )
144
155
} )
145
156
146
- it . skip ( 'returns no peers within 10 seconds' , ( done ) => {
157
+ it ( 'returns no peers within 10 seconds' , ( done ) => {
147
158
// Currently go-ipfs returns peers that have not been
148
159
// subscribed to the topic. Enable when go-ipfs has been fixed
149
160
ipfs1 . pubsub . subscribe ( topic , ( err , subscription ) => {
@@ -159,7 +170,7 @@ module.exports = (common) => {
159
170
} )
160
171
} )
161
172
162
- it . skip ( 'doesn\'t return extra peers' , ( done ) => {
173
+ it ( 'doesn\'t return extra peers' , ( done ) => {
163
174
// Currently go-ipfs returns peers that have not been
164
175
// subscribed to the topic. Enable when go-ipfs has been fixed
165
176
ipfs1 . pubsub . subscribe ( topic , ( err , subscription1 ) => {
@@ -182,10 +193,16 @@ module.exports = (common) => {
182
193
} )
183
194
} )
184
195
185
- it . skip ( 'returns peers for a topic - one peer' , ( done ) => {
196
+ it ( 'returns peers for a topic - one peer' , ( done ) => {
186
197
// Currently go-ipfs returns peers that have not been subscribed to the topic
187
198
// Enable when go-ipfs has been fixed
188
199
const peersToWait = [ ipfs2 . peerId ]
200
+ let subscription2
201
+
202
+ ipfs1 . pubsub . subscribe ( topic , ( err , subscription ) => {
203
+ expect ( err ) . to . not . exist
204
+ subscription2 = subscription
205
+ } )
189
206
190
207
ipfs2 . pubsub . subscribe ( topic , ( err , subscription ) => {
191
208
expect ( err ) . to . not . exist
@@ -197,8 +214,6 @@ module.exports = (common) => {
197
214
done ( err )
198
215
}
199
216
200
- console . log ( peers )
201
-
202
217
const hasAllPeers = peersToWait
203
218
. map ( ( e ) => peers . indexOf ( e ) !== - 1 )
204
219
. filter ( ( e ) => e === false )
@@ -207,7 +222,9 @@ module.exports = (common) => {
207
222
if ( hasAllPeers ) {
208
223
clearInterval ( i )
209
224
expect ( peers . length ) . to . equal ( peersToWait . length )
210
- subscription . cancel ( done )
225
+ subscription . cancel ( )
226
+ . then ( ( ) => subscription2 . cancel ( ) )
227
+ . then ( done )
211
228
}
212
229
} )
213
230
} , 1000 )
@@ -264,21 +281,30 @@ module.exports = (common) => {
264
281
const ipfs2Addr = id . addresses [ 0 ]
265
282
ipfs1 . swarm . connect ( ipfs2Addr , ( err ) => {
266
283
expect ( err ) . to . not . exist
284
+ // We need to fix this on libp2p level
267
285
setTimeout ( done , 3000 )
268
286
} )
269
287
} )
270
288
} )
271
289
272
290
it ( 'receive messages from different node' , ( done ) => {
273
291
const expectedString = 'hello from the other side'
292
+ let subscription2
293
+
294
+ ipfs2 . pubsub . subscribe ( topic , ( err , subscription ) => {
295
+ expect ( err ) . to . not . exist
296
+ subscription2 = subscription
297
+ } )
274
298
275
299
ipfs1 . pubsub . subscribe ( topic , ( err , subscription ) => {
276
300
expect ( err ) . to . not . exist
277
301
expect ( subscription ) . to . exist
278
302
279
303
subscription . on ( 'data' , ( d ) => {
280
304
expect ( d . data ) . to . be . equal ( expectedString )
281
- subscription . cancel ( done )
305
+ subscription . cancel ( )
306
+ . then ( ( ) => subscription2 . cancel ( ) )
307
+ . then ( done )
282
308
} )
283
309
284
310
waitForPeers ( ipfs2 , [ ipfs1 . peerId ] , ( err ) => {
@@ -293,6 +319,12 @@ module.exports = (common) => {
293
319
it ( 'receive multiple messages' , ( done ) => {
294
320
let receivedMessages = [ ]
295
321
const expectedMessages = 2
322
+ let subscription2
323
+
324
+ ipfs2 . pubsub . subscribe ( topic , ( err , subscription ) => {
325
+ expect ( err ) . to . not . exist
326
+ subscription2 = subscription
327
+ } )
296
328
297
329
ipfs1 . pubsub . subscribe ( topic , ( err , subscription ) => {
298
330
expect ( err ) . to . not . exists
@@ -303,7 +335,9 @@ module.exports = (common) => {
303
335
receivedMessages . forEach ( ( msg ) => {
304
336
expect ( msg ) . to . be . equal ( 'hi' )
305
337
} )
306
- subscription . cancel ( done )
338
+ subscription . cancel ( )
339
+ . then ( ( ) => subscription2 . cancel ( ) )
340
+ . then ( done )
307
341
}
308
342
} )
309
343
@@ -317,12 +351,30 @@ module.exports = (common) => {
317
351
} )
318
352
319
353
describe ( 'load tests' , ( ) => {
354
+ before ( ( done ) => {
355
+ ipfs2 . id ( ( err , id ) => {
356
+ expect ( err ) . to . not . exist
357
+ const ipfs2Addr = id . addresses [ 0 ]
358
+ ipfs1 . swarm . connect ( ipfs2Addr , ( err ) => {
359
+ expect ( err ) . to . not . exist
360
+ // We need to fix this on libp2p level
361
+ setTimeout ( done , 3000 )
362
+ } )
363
+ } )
364
+ } )
365
+
320
366
it ( 'send/receive 10k messages' , ( done ) => {
321
367
const expectedString = 'hello'
322
368
const count = 10000
323
369
let sendCount = 0
324
370
let receivedCount = 0
325
371
let startTime
372
+ let subscription2
373
+
374
+ ipfs2 . pubsub . subscribe ( topic , ( err , subscription ) => {
375
+ expect ( err ) . to . not . exists
376
+ subscription2 = subscription
377
+ } )
326
378
327
379
ipfs1 . pubsub . subscribe ( topic , ( err , subscription ) => {
328
380
expect ( err ) . to . not . exists
@@ -340,7 +392,9 @@ module.exports = (common) => {
340
392
const duration = new Date ( ) . getTime ( ) - startTime
341
393
process . stdout . write ( ' \r' )
342
394
console . log ( `Send/Receive 10k messages took: ${ duration } ms, ${ Math . floor ( count / ( duration / 1000 ) ) } ops / s` )
343
- subscription . cancel ( done )
395
+ subscription . cancel ( )
396
+ . then ( ( ) => subscription2 . cancel ( ) )
397
+ . then ( done )
344
398
}
345
399
} )
346
400
0 commit comments