From 5eadaff4e1caa0f48b66bb730cfd5a678fe8d16e Mon Sep 17 00:00:00 2001 From: haad Date: Fri, 9 Dec 2016 11:50:05 +0100 Subject: [PATCH] Fix 10k load test (send only 2k). Fix "not subscribed" errors in multi-node tests --- src/pubsub.js | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/src/pubsub.js b/src/pubsub.js index ecf5fed8..93f0a401 100644 --- a/src/pubsub.js +++ b/src/pubsub.js @@ -271,6 +271,12 @@ module.exports = (common) => { it('receive messages from different node', (done) => { const expectedString = 'hello from the other side' + let subscription2 + + ipfs2.pubsub.subscribe(topic, (err, subscription) => { + expect(err).to.not.exist + subscription2 = subscription + }) ipfs1.pubsub.subscribe(topic, (err, subscription) => { expect(err).to.not.exist @@ -278,7 +284,9 @@ module.exports = (common) => { subscription.on('data', (d) => { expect(d.data).to.be.equal(expectedString) - subscription.cancel(done) + subscription.cancel() + .then(() => subscription2.cancel()) + .then(done) }) waitForPeers(ipfs2, [ipfs1.peerId], (err) => { @@ -293,6 +301,12 @@ module.exports = (common) => { it('receive multiple messages', (done) => { let receivedMessages = [] const expectedMessages = 2 + let subscription2 + + ipfs2.pubsub.subscribe(topic, (err, subscription) => { + expect(err).to.not.exist + subscription2 = subscription + }) ipfs1.pubsub.subscribe(topic, (err, subscription) => { expect(err).to.not.exists @@ -303,7 +317,9 @@ module.exports = (common) => { receivedMessages.forEach((msg) => { expect(msg).to.be.equal('hi') }) - subscription.cancel(done) + subscription.cancel() + .then(() => subscription2.cancel()) + .then(done) } }) @@ -317,12 +333,30 @@ module.exports = (common) => { }) describe('load tests', () => { + before((done) => { + ipfs2.id((err, id) => { + expect(err).to.not.exist + const ipfs2Addr = id.addresses[0] + ipfs1.swarm.connect(ipfs2Addr, (err) => { + expect(err).to.not.exist + // We need to fix this on libp2p level + setTimeout(done, 3000) + }) + }) + }) + it('send/receive 10k messages', (done) => { const expectedString = 'hello' - const count = 10000 + const count = 2000 let sendCount = 0 let receivedCount = 0 let startTime + let subscription2 + + ipfs2.pubsub.subscribe(topic, (err, subscription) => { + expect(err).to.not.exists + subscription2 = subscription + }) ipfs1.pubsub.subscribe(topic, (err, subscription) => { expect(err).to.not.exists @@ -340,7 +374,9 @@ module.exports = (common) => { const duration = new Date().getTime() - startTime process.stdout.write(' \r') console.log(`Send/Receive 10k messages took: ${duration} ms, ${Math.floor(count / (duration / 1000))} ops / s`) - subscription.cancel(done) + subscription.cancel() + .then(() => subscription2.cancel()) + .then(done) } })