From f5b569ca645441c203c15b70add5c3a1d1151fa6 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 31 May 2019 14:28:36 +0100 Subject: [PATCH 1/2] fix: dht tests closes https://github.com/ipfs/interface-js-ipfs-core/pull/383 License: MIT Signed-off-by: Alan Shaw --- src/dht/get.js | 19 +++++++++---------- src/dht/index.js | 2 +- src/dht/put.js | 27 ++++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/dht/get.js b/src/dht/get.js index 38c6409e..d65b9607 100644 --- a/src/dht/get.js +++ b/src/dht/get.js @@ -1,7 +1,9 @@ /* eslint-env mocha */ 'use strict' +const hat = require('hat') const waterfall = require('async/waterfall') +const retry = require('async/retry') const { spawnNodesWithId } = require('../utils/spawn') const { getDescribe, getIt, expect } = require('../utils/mocha') const { connect } = require('../utils/swarm') @@ -43,7 +45,7 @@ module.exports = (createCommon, options) => { }) it('should error when getting a non-existent key from the DHT', (done) => { - nodeA.dht.get('non-existing', { timeout: '100ms' }, (err, value) => { + nodeA.dht.get('non-existing', { timeout: 100 }, (err, value) => { expect(err).to.be.an.instanceof(Error) done() }) @@ -52,17 +54,14 @@ module.exports = (createCommon, options) => { it('should get a value after it was put on another node', function (done) { this.timeout(80 * 1000) - // TODO - this test needs to keep tryingl instead of the setTimeout - waterfall([ - (cb) => nodeB.object.new('unixfs-dir', cb), - (dagNode, cb) => setTimeout(() => cb(null, dagNode), 20000), - (dagNode, cb) => { - const multihash = dagNode.toJSON().multihash + const key = Buffer.from(hat()) + const value = Buffer.from(hat()) - nodeA.dht.get(multihash, cb) - }, + waterfall([ + cb => nodeB.dht.put(key, value, cb), + cb => nodeA.dht.get(key, cb), (result, cb) => { - expect(result).to.eql('') + expect(result).to.eql(value) cb() } ], done) diff --git a/src/dht/index.js b/src/dht/index.js index c9099fad..f3a66aac 100644 --- a/src/dht/index.js +++ b/src/dht/index.js @@ -2,8 +2,8 @@ const { createSuite } = require('../utils/suite') const tests = { - get: require('./get'), put: require('./put'), + get: require('./get'), findPeer: require('./find-peer'), provide: require('./provide'), findProvs: require('./find-provs'), diff --git a/src/dht/put.js b/src/dht/put.js index df07c231..a1c39794 100644 --- a/src/dht/put.js +++ b/src/dht/put.js @@ -1,7 +1,9 @@ /* eslint-env mocha */ 'use strict' +const { spawnNodesWithId } = require('../utils/spawn') const { getDescribe, getIt, expect } = require('../utils/mocha') +const { connect } = require('../utils/swarm') module.exports = (createCommon, options) => { const describe = getDescribe(options) @@ -9,6 +11,11 @@ module.exports = (createCommon, options) => { const common = createCommon() describe('.dht.put', function () { + this.timeout(80 * 1000) + + let nodeA + let nodeB + before(function (done) { // CI takes longer to instantiate the daemon, so we need to increase the // timeout for the before step @@ -16,14 +23,28 @@ module.exports = (createCommon, options) => { common.setup((err, factory) => { expect(err).to.not.exist() - done() + + spawnNodesWithId(2, factory, (err, nodes) => { + expect(err).to.not.exist() + + nodeA = nodes[0] + nodeB = nodes[1] + connect(nodeA, nodeB.peerId.addresses[0], done) + }) }) }) after((done) => common.teardown(done)) - it.skip('should put a value on the DHT', (done) => { - // TODO: implement me + it('should put a value to the DHT', (done) => { + this.timeout(80 * 1000) + const key = Buffer.from('QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn') + const data = Buffer.from('data') + + nodeA.dht.put(key, data, (err) => { + expect(err).to.not.exist() + done() + }) }) }) } From a6cfe6e32b58bec22141a9234463269500cf80bf Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 31 May 2019 14:29:58 +0100 Subject: [PATCH 2/2] fix: remove unused var License: MIT Signed-off-by: Alan Shaw --- src/dht/get.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/dht/get.js b/src/dht/get.js index d65b9607..c3d053a5 100644 --- a/src/dht/get.js +++ b/src/dht/get.js @@ -3,7 +3,6 @@ const hat = require('hat') const waterfall = require('async/waterfall') -const retry = require('async/retry') const { spawnNodesWithId } = require('../utils/spawn') const { getDescribe, getIt, expect } = require('../utils/mocha') const { connect } = require('../utils/swarm')