@@ -271,14 +271,22 @@ module.exports = (common) => {
271
271
272
272
it ( 'receive messages from different node' , ( done ) => {
273
273
const expectedString = 'hello from the other side'
274
+ let subscription2
275
+
276
+ ipfs2 . pubsub . subscribe ( topic , ( err , subscription ) => {
277
+ expect ( err ) . to . not . exist
278
+ subscription2 = subscription
279
+ } )
274
280
275
281
ipfs1 . pubsub . subscribe ( topic , ( err , subscription ) => {
276
282
expect ( err ) . to . not . exist
277
283
expect ( subscription ) . to . exist
278
284
279
285
subscription . on ( 'data' , ( d ) => {
280
286
expect ( d . data ) . to . be . equal ( expectedString )
281
- subscription . cancel ( done )
287
+ subscription . cancel ( )
288
+ . then ( ( ) => subscription2 . cancel ( ) )
289
+ . then ( done )
282
290
} )
283
291
284
292
waitForPeers ( ipfs2 , [ ipfs1 . peerId ] , ( err ) => {
@@ -293,6 +301,12 @@ module.exports = (common) => {
293
301
it ( 'receive multiple messages' , ( done ) => {
294
302
let receivedMessages = [ ]
295
303
const expectedMessages = 2
304
+ let subscription2
305
+
306
+ ipfs2 . pubsub . subscribe ( topic , ( err , subscription ) => {
307
+ expect ( err ) . to . not . exist
308
+ subscription2 = subscription
309
+ } )
296
310
297
311
ipfs1 . pubsub . subscribe ( topic , ( err , subscription ) => {
298
312
expect ( err ) . to . not . exists
@@ -303,7 +317,9 @@ module.exports = (common) => {
303
317
receivedMessages . forEach ( ( msg ) => {
304
318
expect ( msg ) . to . be . equal ( 'hi' )
305
319
} )
306
- subscription . cancel ( done )
320
+ subscription . cancel ( )
321
+ . then ( ( ) => subscription2 . cancel ( ) )
322
+ . then ( done )
307
323
}
308
324
} )
309
325
@@ -317,12 +333,30 @@ module.exports = (common) => {
317
333
} )
318
334
319
335
describe ( 'load tests' , ( ) => {
336
+ before ( ( done ) => {
337
+ ipfs2 . id ( ( err , id ) => {
338
+ expect ( err ) . to . not . exist
339
+ const ipfs2Addr = id . addresses [ 0 ]
340
+ ipfs1 . swarm . connect ( ipfs2Addr , ( err ) => {
341
+ expect ( err ) . to . not . exist
342
+ // We need to fix this on libp2p level
343
+ setTimeout ( done , 3000 )
344
+ } )
345
+ } )
346
+ } )
347
+
320
348
it ( 'send/receive 10k messages' , ( done ) => {
321
349
const expectedString = 'hello'
322
- const count = 10000
350
+ const count = 2000
323
351
let sendCount = 0
324
352
let receivedCount = 0
325
353
let startTime
354
+ let subscription2
355
+
356
+ ipfs2 . pubsub . subscribe ( topic , ( err , subscription ) => {
357
+ expect ( err ) . to . not . exists
358
+ subscription2 = subscription
359
+ } )
326
360
327
361
ipfs1 . pubsub . subscribe ( topic , ( err , subscription ) => {
328
362
expect ( err ) . to . not . exists
@@ -340,7 +374,9 @@ module.exports = (common) => {
340
374
const duration = new Date ( ) . getTime ( ) - startTime
341
375
process . stdout . write ( ' \r' )
342
376
console . log ( `Send/Receive 10k messages took: ${ duration } ms, ${ Math . floor ( count / ( duration / 1000 ) ) } ops / s` )
343
- subscription . cancel ( done )
377
+ subscription . cancel ( )
378
+ . then ( ( ) => subscription2 . cancel ( ) )
379
+ . then ( done )
344
380
}
345
381
} )
346
382
0 commit comments