From 7e09eae7e50fcfceb29364f6465c0e0a3f8b1bfd Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Wed, 10 Jul 2019 23:01:31 +0100 Subject: [PATCH 1/2] test: add find providers test for multiple providers License: MIT Signed-off-by: Jacob Heun --- src/dht/find-provs.js | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/dht/find-provs.js b/src/dht/find-provs.js index 3ee87cf29..0c93309ed 100644 --- a/src/dht/find-provs.js +++ b/src/dht/find-provs.js @@ -3,6 +3,7 @@ const multihashing = require('multihashing-async') const waterfall = require('async/waterfall') +const parallel = require('async/parallel') const CID = require('cids') const { spawnNodesWithId } = require('../utils/spawn') const { getDescribe, getIt, expect } = require('../utils/mocha') @@ -26,6 +27,7 @@ module.exports = (createCommon, options) => { describe('.dht.findProvs', function () { let nodeA let nodeB + let nodeC before(function (done) { // CI takes longer to instantiate the daemon, so we need to increase the @@ -35,35 +37,54 @@ module.exports = (createCommon, options) => { common.setup((err, factory) => { expect(err).to.not.exist() - spawnNodesWithId(2, factory, (err, nodes) => { + spawnNodesWithId(3, factory, (err, nodes) => { expect(err).to.not.exist() nodeA = nodes[0] nodeB = nodes[1] + nodeC = nodes[2] - connect(nodeB, nodeA.peerId.addresses[0], done) + parallel([ + (cb) => connect(nodeB, nodeA.peerId.addresses[0], cb), + (cb) => connect(nodeC, nodeB.peerId.addresses[0], cb) + ], done) }) }) }) + let providedCid + before('add providers for the same cid', function (done) { + this.timeout(10 * 1000) + parallel([ + (cb) => nodeB.object.new('unixfs-dir', cb), + (cb) => nodeC.object.new('unixfs-dir', cb), + ], (err, cids) => { + if (err) return done(err) + providedCid = cids[0] + parallel([ + (cb) => nodeB.dht.provide(providedCid, cb), + (cb) => nodeC.dht.provide(providedCid, cb), + ], done) + }) + }) + after(function (done) { this.timeout(50 * 1000) common.teardown(done) }) - it('should provide from one node and find it through another node', function (done) { - this.timeout(80 * 1000) + it('should be able to find providers', function (done) { + this.timeout(20 * 1000) waterfall([ - (cb) => nodeB.object.new('unixfs-dir', cb), - (cid, cb) => { - nodeB.dht.provide(cid, (err) => cb(err, cid)) - }, - (cid, cb) => nodeA.dht.findProvs(cid, cb), + (cb) => nodeA.dht.findProvs(providedCid, cb), (provs, cb) => { - expect(provs.map((p) => p.id.toB58String())) - .to.eql([nodeB.peerId.id]) + const providerIds = provs.map((p) => p.id.toB58String()) + expect(providerIds).to.have.members([ + nodeB.peerId.id, + nodeC.peerId.id, + ]) cb() } ], done) From d566fe82d99e985d35a7ff2599ffc043c00ca98d Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Wed, 10 Jul 2019 23:05:39 +0100 Subject: [PATCH 2/2] chore: fix linting License: MIT Signed-off-by: Jacob Heun --- src/dht/find-provs.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dht/find-provs.js b/src/dht/find-provs.js index 0c93309ed..478eb0d20 100644 --- a/src/dht/find-provs.js +++ b/src/dht/find-provs.js @@ -57,13 +57,13 @@ module.exports = (createCommon, options) => { this.timeout(10 * 1000) parallel([ (cb) => nodeB.object.new('unixfs-dir', cb), - (cb) => nodeC.object.new('unixfs-dir', cb), + (cb) => nodeC.object.new('unixfs-dir', cb) ], (err, cids) => { if (err) return done(err) providedCid = cids[0] parallel([ (cb) => nodeB.dht.provide(providedCid, cb), - (cb) => nodeC.dht.provide(providedCid, cb), + (cb) => nodeC.dht.provide(providedCid, cb) ], done) }) }) @@ -83,7 +83,7 @@ module.exports = (createCommon, options) => { const providerIds = provs.map((p) => p.id.toB58String()) expect(providerIds).to.have.members([ nodeB.peerId.id, - nodeC.peerId.id, + nodeC.peerId.id ]) cb() }