From ad952e20d6bb0dab254fea39efd2f3cb224ce9ad Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 12 Jan 2017 14:01:46 +0000 Subject: [PATCH] fix(test): send/receive 10k messages test --- src/pubsub.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/pubsub.js b/src/pubsub.js index 4402eb7c5c..4fa329617c 100644 --- a/src/pubsub.js +++ b/src/pubsub.js @@ -447,29 +447,25 @@ module.exports = (common) => { it('send/receive 10k messages', function (done) { this.timeout(2 * 60 * 1000) - const msgData = new Buffer('hello') + const msgBase = 'msg - ' const count = 10000 let sendCount = 0 let receivedCount = 0 let startTime let counter = 0 - function check () { - if (++counter === 2) { - ipfs1.pubsub.unsubscribe(topic, sub1) - ipfs2.pubsub.unsubscribe(topic, sub2) - done() - } - } - const sub1 = (msg) => { - expect(msg.data).to.eql(msgData) + const expectedMsg = msgBase + receivedCount + const receivedMsg = msg.data.toString() + expect(receivedMsg).to.eql(expectedMsg) receivedCount++ if (receivedCount >= count) { const duration = new Date().getTime() - startTime - console.log(`Send/Receive 10k messages took: ${duration} ms, ${Math.floor(count / (duration / 1000))} ops / s\n`) + const opsPerSec = Math.floor(count / (duration / 1000)) + + console.log(`Send/Receive 10k messages took: ${duration} ms, ${opsPerSec} ops / s\n`) check() } @@ -477,6 +473,14 @@ module.exports = (common) => { const sub2 = (msg) => {} + function check () { + if (++counter === 2) { + ipfs1.pubsub.unsubscribe(topic, sub1) + ipfs2.pubsub.unsubscribe(topic, sub2) + done() + } + } + series([ (cb) => ipfs1.pubsub.subscribe(topic, sub1, cb), (cb) => ipfs2.pubsub.subscribe(topic, sub2, cb), @@ -488,6 +492,7 @@ module.exports = (common) => { whilst( () => sendCount < count, (cb) => { + const msgData = new Buffer(msgBase + sendCount) sendCount++ ipfs2.pubsub.publish(topic, msgData, cb) },