Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit ad952e2

Browse files
committed
fix(test): send/receive 10k messages test
1 parent e449029 commit ad952e2

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/pubsub.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -447,36 +447,40 @@ module.exports = (common) => {
447447
it('send/receive 10k messages', function (done) {
448448
this.timeout(2 * 60 * 1000)
449449

450-
const msgData = new Buffer('hello')
450+
const msgBase = 'msg - '
451451
const count = 10000
452452
let sendCount = 0
453453
let receivedCount = 0
454454
let startTime
455455
let counter = 0
456456

457-
function check () {
458-
if (++counter === 2) {
459-
ipfs1.pubsub.unsubscribe(topic, sub1)
460-
ipfs2.pubsub.unsubscribe(topic, sub2)
461-
done()
462-
}
463-
}
464-
465457
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)
467461

468462
receivedCount++
469463

470464
if (receivedCount >= count) {
471465
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`)
473469

474470
check()
475471
}
476472
}
477473

478474
const sub2 = (msg) => {}
479475

476+
function check () {
477+
if (++counter === 2) {
478+
ipfs1.pubsub.unsubscribe(topic, sub1)
479+
ipfs2.pubsub.unsubscribe(topic, sub2)
480+
done()
481+
}
482+
}
483+
480484
series([
481485
(cb) => ipfs1.pubsub.subscribe(topic, sub1, cb),
482486
(cb) => ipfs2.pubsub.subscribe(topic, sub2, cb),
@@ -488,6 +492,7 @@ module.exports = (common) => {
488492
whilst(
489493
() => sendCount < count,
490494
(cb) => {
495+
const msgData = new Buffer(msgBase + sendCount)
491496
sendCount++
492497
ipfs2.pubsub.publish(topic, msgData, cb)
493498
},

0 commit comments

Comments
 (0)