Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix(test): send/receive 10k messages test
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Jan 16, 2017
1 parent e449029 commit ad952e2
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,36 +447,40 @@ 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()
}
}

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),
Expand All @@ -488,6 +492,7 @@ module.exports = (common) => {
whilst(
() => sendCount < count,
(cb) => {
const msgData = new Buffer(msgBase + sendCount)
sendCount++
ipfs2.pubsub.publish(topic, msgData, cb)
},
Expand Down

0 comments on commit ad952e2

Please sign in to comment.