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

Commit 54336dd

Browse files
jhieseyvasco-santos
authored andcommitted
fix: make 'find peer query' test reliable (#58)
1 parent 60dc71e commit 54336dd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

test/kad-dht.spec.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -586,15 +586,18 @@ describe('KadDHT', () => {
586586
const guy = dhts[0]
587587
const others = dhts.slice(1)
588588
const val = Buffer.from('foobar')
589+
const connected = {} // indexes in others that are reachable from guy
589590

590591
series([
591592
(cb) => times(20, (i, cb) => {
592593
times(16, (j, cb) => {
593594
const t = 20 + random(79)
595+
connected[t] = true
594596
connect(others[i], others[t], cb)
595597
}, cb)
596598
}, cb),
597599
(cb) => times(20, (i, cb) => {
600+
connected[i] = true
598601
connect(guy, others[i], cb)
599602
}, cb),
600603
(cb) => kadUtils.convertBuffer(val, (err, rtval) => {
@@ -610,9 +613,11 @@ describe('KadDHT', () => {
610613
rtableSet[p.toB58String()] = true
611614
})
612615

616+
const connectedIds = ids.slice(1).filter((id, i) => connected[i])
617+
613618
series([
614619
(cb) => guy.getClosestPeers(val, cb),
615-
(cb) => kadUtils.sortClosestPeers(ids.slice(1), rtval, cb)
620+
(cb) => kadUtils.sortClosestPeers(connectedIds, rtval, cb)
616621
], (err, res) => {
617622
expect(err).to.not.exist()
618623
const out = res[0]

0 commit comments

Comments
 (0)