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

Commit 60c0747

Browse files
committed
test: augment dht tests, disable the ones that are wonky for go just for go
1 parent 2d227a9 commit 60c0747

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

js/src/dht.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ const CID = require('cids')
1111
const { spawnNodesWithId } = require('./utils/spawn')
1212

1313
module.exports = (common) => {
14-
describe('.dht', function () {
14+
describe.only('.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,19 @@ 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+
if (withGo) {
74+
// go-ipfs errors with Error: key was not found (type 6)
75+
// https://github.com/ipfs/go-ipfs/issues/3862
76+
this.skip()
77+
}
78+
79+
// TODO - this test needs to keep tryingl instead of the setTimeout
6980
waterfall([
7081
(cb) => nodeB.object.new('unixfs-dir', cb),
71-
(node, cb) => setTimeout(() => cb(null, node), 1000),
72-
(node, cb) => {
73-
const multihash = node.toJSON().multihash
82+
(dagNode, cb) => setTimeout(() => cb(null, dagNode), 1000),
83+
(dagNode, cb) => {
84+
const multihash = dagNode.toJSON().multihash
7485

7586
nodeA.dht.get(multihash, cb)
7687
},
@@ -80,14 +91,6 @@ module.exports = (common) => {
8091
}
8192
], done)
8293
})
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-
})
9194
})
9295

9396
describe('.findpeer', () => {
@@ -100,9 +103,13 @@ module.exports = (common) => {
100103
})
101104
})
102105

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) => {
106+
it('fails to find other peer, if peer does not exist', function (done) {
107+
if (withGo) {
108+
// TODO checking what is exactly go-ipfs returning
109+
// https://github.com/ipfs/go-ipfs/issues/3862#issuecomment-294168090
110+
this.skip()
111+
}
112+
106113
nodeA.dht.findpeer('Qmd7qZS4T7xXtsNFdRoK1trfMs5zU94EpokQ9WFtxdPxsZ', (err, peer) => {
107114
expect(err).to.not.exist()
108115
expect(peer).to.be.equal(null)
@@ -177,37 +184,30 @@ module.exports = (common) => {
177184
it.skip('recursive', () => {})
178185
})
179186

180-
describe.skip('findprovs', () => {
187+
describe('findprovs', () => {
181188
it('basic', (done) => {
182-
const cid = new CID('Qmd7qZS4T7xXtsNFdRoK1trfMs5zU94EpokQ9WFtxdPxxx')
183-
184189
waterfall([
185-
(cb) => nodeB.dht.provide(cid, cb),
186-
(cb) => nodeC.dht.findprovs(cid, cb),
190+
(cb) => nodeE.object.new('unixfs-dir', cb),
191+
(dagNode, cb) => {
192+
const cidV0 = new CID(dagNode.toJSON().multihash)
193+
nodeE.dht.provide(cidV0, (err) => cb(err, cidV0))
194+
},
195+
(cidV0, cb) => nodeC.dht.findprovs(cidV0, cb),
187196
(provs, cb) => {
188197
expect(provs.map((p) => p.toB58String()))
189-
.to.eql([nodeB.peerId.id])
198+
.to.eql([nodeE.peerId.id])
190199
cb()
191200
}
192201
], done)
193202
})
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-
})
203203
})
204204

205205
describe('.query', () => {
206206
it('returns the other node in the query', function (done) {
207207
const timeout = 150 * 1000
208208
this.timeout(timeout)
209209

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

0 commit comments

Comments
 (0)