@@ -447,36 +447,40 @@ module.exports = (common) => {
447
447
it ( 'send/receive 10k messages' , function ( done ) {
448
448
this . timeout ( 2 * 60 * 1000 )
449
449
450
- const msgData = new Buffer ( 'hello' )
450
+ const msgBase = 'msg - '
451
451
const count = 10000
452
452
let sendCount = 0
453
453
let receivedCount = 0
454
454
let startTime
455
455
let counter = 0
456
456
457
- function check ( ) {
458
- if ( ++ counter === 2 ) {
459
- ipfs1 . pubsub . unsubscribe ( topic , sub1 )
460
- ipfs2 . pubsub . unsubscribe ( topic , sub2 )
461
- done ( )
462
- }
463
- }
464
-
465
457
const sub1 = ( msg ) => {
466
- expect ( msg . data ) . to . eql ( msgData )
458
+ const expectedMsg = msgBase + receivedCount
459
+ const receivedMsg = msg . data . toString ( )
460
+ expect ( receivedMsg ) . to . eql ( expectedMsg )
467
461
468
462
receivedCount ++
469
463
470
464
if ( receivedCount >= count ) {
471
465
const duration = new Date ( ) . getTime ( ) - startTime
472
- console . log ( `Send/Receive 10k messages took: ${ duration } ms, ${ Math . floor ( count / ( duration / 1000 ) ) } ops / s\n` )
466
+ const opsPerSec = Math . floor ( count / ( duration / 1000 ) )
467
+
468
+ console . log ( `Send/Receive 10k messages took: ${ duration } ms, ${ opsPerSec } ops / s\n` )
473
469
474
470
check ( )
475
471
}
476
472
}
477
473
478
474
const sub2 = ( msg ) => { }
479
475
476
+ function check ( ) {
477
+ if ( ++ counter === 2 ) {
478
+ ipfs1 . pubsub . unsubscribe ( topic , sub1 )
479
+ ipfs2 . pubsub . unsubscribe ( topic , sub2 )
480
+ done ( )
481
+ }
482
+ }
483
+
480
484
series ( [
481
485
( cb ) => ipfs1 . pubsub . subscribe ( topic , sub1 , cb ) ,
482
486
( cb ) => ipfs2 . pubsub . subscribe ( topic , sub2 , cb ) ,
@@ -488,6 +492,7 @@ module.exports = (common) => {
488
492
whilst (
489
493
( ) => sendCount < count ,
490
494
( cb ) => {
495
+ const msgData = new Buffer ( msgBase + sendCount )
491
496
sendCount ++
492
497
ipfs2 . pubsub . publish ( topic , msgData , cb )
493
498
} ,
0 commit comments