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

Commit d5c28ae

Browse files
authored
test: augment dht tests (first pass) (#288)
* test: augment dht tests, disable the ones that are wonky for go just for go * test: skip findprovs test in go until the issue has been fixed * test: remove .only
1 parent 60c30fc commit d5c28ae

File tree

1 file changed

+42
-34
lines changed

1 file changed

+42
-34
lines changed

js/src/dht.js

+42-34
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = (common) => {
1414
describe('.dht', function () {
1515
this.timeout(80 * 1000)
1616

17+
let withGo
1718
let nodeA
1819
let nodeB
1920
let nodeC
@@ -47,7 +48,12 @@ module.exports = (common) => {
4748
(cb) => nodeE.swarm.connect(nodeB.peerId.addresses[0], cb),
4849
(cb) => nodeD.swarm.connect(nodeC.peerId.addresses[0], cb),
4950
(cb) => nodeE.swarm.connect(nodeC.peerId.addresses[0], cb),
50-
(cb) => nodeD.swarm.connect(nodeE.peerId.addresses[0], cb)
51+
(cb) => nodeD.swarm.connect(nodeE.peerId.addresses[0], cb),
52+
(cb) => nodeA.id((err, id) => {
53+
expect(err).to.not.exist()
54+
withGo = id.agentVersion.startsWith('go-ipfs')
55+
cb()
56+
})
5157
], done)
5258
})
5359
})
@@ -63,14 +69,21 @@ module.exports = (common) => {
6369
})
6470
})
6571

66-
// TODO: fix - go-ipfs errors with Error: key was not found (type 6)
67-
// https://github.com/ipfs/go-ipfs/issues/3862
68-
it.skip('fetches value after it was put on another node', (done) => {
72+
it('fetches value after it was put on another node', function (done) {
73+
this.timeout(80 * 1000)
74+
75+
if (withGo) {
76+
// go-ipfs errors with Error: key was not found (type 6)
77+
// https://github.com/ipfs/go-ipfs/issues/3862
78+
this.skip()
79+
}
80+
81+
// TODO - this test needs to keep tryingl instead of the setTimeout
6982
waterfall([
7083
(cb) => nodeB.object.new('unixfs-dir', cb),
71-
(node, cb) => setTimeout(() => cb(null, node), 1000),
72-
(node, cb) => {
73-
const multihash = node.toJSON().multihash
84+
(dagNode, cb) => setTimeout(() => cb(null, dagNode), 20000),
85+
(dagNode, cb) => {
86+
const multihash = dagNode.toJSON().multihash
7487

7588
nodeA.dht.get(multihash, cb)
7689
},
@@ -80,14 +93,6 @@ module.exports = (common) => {
8093
}
8194
], done)
8295
})
83-
84-
it('Promises support', (done) => {
85-
nodeA.dht.get('non-existing', { timeout: '100ms' })
86-
.catch((err) => {
87-
expect(err).to.exist()
88-
done()
89-
})
90-
})
9196
})
9297

9398
describe('.findpeer', () => {
@@ -100,9 +105,13 @@ module.exports = (common) => {
100105
})
101106
})
102107

103-
// TODO checking what is exactly go-ipfs returning
104-
// https://github.com/ipfs/go-ipfs/issues/3862#issuecomment-294168090
105-
it.skip('fails to find other peer, if peer doesnt exist()s', (done) => {
108+
it('fails to find other peer, if peer does not exist', function (done) {
109+
if (withGo) {
110+
// TODO checking what is exactly go-ipfs returning
111+
// https://github.com/ipfs/go-ipfs/issues/3862#issuecomment-294168090
112+
this.skip()
113+
}
114+
106115
nodeA.dht.findpeer('Qmd7qZS4T7xXtsNFdRoK1trfMs5zU94EpokQ9WFtxdPxsZ', (err, peer) => {
107116
expect(err).to.not.exist()
108117
expect(peer).to.be.equal(null)
@@ -177,37 +186,36 @@ module.exports = (common) => {
177186
it.skip('recursive', () => {})
178187
})
179188

180-
describe.skip('findprovs', () => {
181-
it('basic', (done) => {
182-
const cid = new CID('Qmd7qZS4T7xXtsNFdRoK1trfMs5zU94EpokQ9WFtxdPxxx')
189+
describe('findprovs', () => {
190+
it('provide from one node and find it through another node', function (done) {
191+
if (withGo) {
192+
// TODO go-ipfs endpoint doesn't conform with the others
193+
// https://github.com/ipfs/go-ipfs/issues/5047
194+
this.skip()
195+
}
183196

184197
waterfall([
185-
(cb) => nodeB.dht.provide(cid, cb),
186-
(cb) => nodeC.dht.findprovs(cid, cb),
198+
(cb) => nodeE.object.new('unixfs-dir', cb),
199+
(dagNode, cb) => {
200+
const cidV0 = new CID(dagNode.toJSON().multihash)
201+
nodeE.dht.provide(cidV0, (err) => cb(err, cidV0))
202+
},
203+
(cidV0, cb) => nodeC.dht.findprovs(cidV0, cb),
187204
(provs, cb) => {
188205
expect(provs.map((p) => p.toB58String()))
189-
.to.eql([nodeB.peerId.id])
206+
.to.eql([nodeE.peerId.id])
190207
cb()
191208
}
192209
], done)
193210
})
194-
195-
it('Promises support', (done) => {
196-
nodeB.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP')
197-
.then((res) => {
198-
expect(res).to.be.an('array')
199-
done()
200-
})
201-
.catch((err) => done(err))
202-
})
203211
})
204212

205213
describe('.query', () => {
206214
it('returns the other node in the query', function (done) {
207215
const timeout = 150 * 1000
208216
this.timeout(timeout)
209217

210-
// This test is flaky. DHT works best with >= 20 nodes. Therefore a
218+
// This test is meh. DHT works best with >= 20 nodes. Therefore a
211219
// failure might happen, but we don't want to report it as such.
212220
// Hence skip the test before the timeout is reached
213221
const timeoutId = setTimeout(function () {

0 commit comments

Comments
 (0)