Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

fix: make 'find peer query' test reliable #58

Merged
merged 1 commit into from
Dec 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion test/kad-dht.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,15 +586,18 @@ describe('KadDHT', () => {
const guy = dhts[0]
const others = dhts.slice(1)
const val = Buffer.from('foobar')
const connected = {} // indexes in others that are reachable from guy

series([
(cb) => times(20, (i, cb) => {
times(16, (j, cb) => {
const t = 20 + random(79)
connected[t] = true
connect(others[i], others[t], cb)
}, cb)
}, cb),
(cb) => times(20, (i, cb) => {
connected[i] = true
connect(guy, others[i], cb)
}, cb),
(cb) => kadUtils.convertBuffer(val, (err, rtval) => {
Expand All @@ -610,9 +613,11 @@ describe('KadDHT', () => {
rtableSet[p.toB58String()] = true
})

const connectedIds = ids.slice(1).filter((id, i) => connected[i])

series([
(cb) => guy.getClosestPeers(val, cb),
(cb) => kadUtils.sortClosestPeers(ids.slice(1), rtval, cb)
(cb) => kadUtils.sortClosestPeers(connectedIds, rtval, cb)
], (err, res) => {
expect(err).to.not.exist()
const out = res[0]
Expand Down