Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
fix: update dht tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Oct 29, 2018
1 parent 332cefb commit 572194e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
29 changes: 27 additions & 2 deletions js/src/dht/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module.exports = (createCommon, options) => {

nodeA = nodes[0]
nodeB = nodes[1]

connect(nodeA, nodeB.peerId.addresses[0], done)
})
})
Expand All @@ -45,7 +44,7 @@ module.exports = (createCommon, options) => {
})
})

it('should get a value after it was put on another node', function (done) {
it.skip('should get a value after it was added on another node', function (done) {
this.timeout(80 * 1000)

// TODO - this test needs to keep tryingl instead of the setTimeout
Expand All @@ -63,5 +62,31 @@ module.exports = (createCommon, options) => {
}
], done)
})

it('should get a value after it was put on another node', function (done) {
this.timeout(80 * 1000)
const multihash = Buffer.from('/v/hello')
const data = Buffer.from('data')

// Rewrite validators
nodeA._libp2pNode._dht.validators.v = nodeB._libp2pNode._dht.validators.v = {
func (key, publicKey, callback) {
setImmediate(callback)
},
sign: false
}

// Rewrite selectors
nodeA._libp2pNode._dht.selectors.v = () => 0

waterfall([
(cb) => nodeB.dht.put(multihash, data, cb),
(cb) => nodeA.dht.get(multihash, (err, res) => {
expect(err).to.not.exist()
expect(res).to.eql(data)
cb()
})
], done)
})
})
}
27 changes: 24 additions & 3 deletions js/src/dht/put.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,50 @@
/* 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)
const it = getIt(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
this.timeout(60 * 1000)

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 on the DHT and it become provided by the peer', (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()
})
})
})
}

0 comments on commit 572194e

Please sign in to comment.