@@ -560,64 +560,76 @@ module.exports = (common) => {
560
560
)
561
561
} )
562
562
563
- it ( 'send/receive 10k messages' , ( done ) => {
564
- this . timeout ( 2 * 60 * 1000 )
563
+ describe ( 'send/receive' , ( ) => {
564
+ let topic
565
+ let sub1
566
+ let sub2
565
567
566
- const msgBase = 'msg - '
567
- const count = 10000
568
- let sendCount = 0
569
- let receivedCount = 0
570
- let startTime
571
- let counter = 0
572
- const topic = getTopic ( )
568
+ before ( ( ) => {
569
+ topic = getTopic ( )
570
+ } )
573
571
574
- const sub1 = ( msg ) => {
575
- // go-ipfs can't send messages in order when there are
576
- // only two nodes in the same machine ¯\_(ツ)_/¯
577
- // https://github.com/ipfs/js-ipfs-api/pull/493#issuecomment-289499943
578
- // const expectedMsg = msgBase + receivedCount
579
- // const receivedMsg = msg.data.toString()
580
- // expect(receivedMsg).to.eql(expectedMsg)
572
+ after ( ( ) => {
573
+ ipfs1 . pubsub . unsubscribe ( topic , sub1 )
574
+ ipfs2 . pubsub . unsubscribe ( topic , sub2 )
575
+ } )
581
576
582
- receivedCount ++
577
+ it ( 'send/receive 10k messages' , function ( done ) {
578
+ this . timeout ( 2 * 60 * 1000 )
583
579
584
- if ( receivedCount >= count ) {
585
- const duration = new Date ( ) . getTime ( ) - startTime
586
- const opsPerSec = Math . floor ( count / ( duration / 1000 ) )
580
+ const msgBase = 'msg - '
581
+ const count = 10000
582
+ let sendCount = 0
583
+ let receivedCount = 0
584
+ let startTime
585
+ let counter = 0
587
586
588
- console . log ( `Send/Receive 10k messages took: ${ duration } ms, ${ opsPerSec } ops / s\n` )
587
+ sub1 = ( msg ) => {
588
+ // go-ipfs can't send messages in order when there are
589
+ // only two nodes in the same machine ¯\_(ツ)_/¯
590
+ // https://github.com/ipfs/js-ipfs-api/pull/493#issuecomment-289499943
591
+ // const expectedMsg = msgBase + receivedCount
592
+ // const receivedMsg = msg.data.toString()
593
+ // expect(receivedMsg).to.eql(expectedMsg)
589
594
590
- check ( )
591
- }
592
- }
595
+ receivedCount ++
593
596
594
- const sub2 = ( msg ) => { }
597
+ if ( receivedCount >= count ) {
598
+ const duration = new Date ( ) . getTime ( ) - startTime
599
+ const opsPerSec = Math . floor ( count / ( duration / 1000 ) )
595
600
596
- function check ( ) {
597
- if ( ++ counter === 2 ) {
598
- ipfs1 . pubsub . unsubscribe ( topic , sub1 )
599
- ipfs2 . pubsub . unsubscribe ( topic , sub2 )
600
- done ( )
601
+ console . log ( `Send/Receive 10k messages took: ${ duration } ms, ${ opsPerSec } ops / s\n` )
602
+
603
+ check ( )
604
+ }
601
605
}
602
- }
603
606
604
- series ( [
605
- ( cb ) => ipfs1 . pubsub . subscribe ( topic , sub1 , cb ) ,
606
- ( cb ) => ipfs2 . pubsub . subscribe ( topic , sub2 , cb ) ,
607
- ( cb ) => waitForPeers ( ipfs1 , topic , [ ipfs2 . peerId . id ] , cb )
608
- ] , ( err ) => {
609
- expect ( err ) . to . not . exist ( )
610
- startTime = new Date ( ) . getTime ( )
607
+ sub2 = ( msg ) => { }
611
608
612
- whilst (
613
- ( ) => sendCount < count ,
614
- ( cb ) => {
615
- const msgData = Buffer . from ( msgBase + sendCount )
616
- sendCount ++
617
- ipfs2 . pubsub . publish ( topic , msgData , cb )
618
- } ,
619
- check
620
- )
609
+ function check ( ) {
610
+ if ( ++ counter === 2 ) {
611
+ done ( )
612
+ }
613
+ }
614
+
615
+ series ( [
616
+ ( cb ) => ipfs1 . pubsub . subscribe ( topic , sub1 , cb ) ,
617
+ ( cb ) => ipfs2 . pubsub . subscribe ( topic , sub2 , cb ) ,
618
+ ( cb ) => waitForPeers ( ipfs1 , topic , [ ipfs2 . peerId . id ] , cb )
619
+ ] , ( err ) => {
620
+ expect ( err ) . to . not . exist ( )
621
+ startTime = new Date ( ) . getTime ( )
622
+
623
+ whilst (
624
+ ( ) => sendCount < count ,
625
+ ( cb ) => {
626
+ const msgData = Buffer . from ( msgBase + sendCount )
627
+ sendCount ++
628
+ ipfs2 . pubsub . publish ( topic , msgData , cb )
629
+ } ,
630
+ check
631
+ )
632
+ } )
621
633
} )
622
634
} )
623
635
0 commit comments