Skip to content

Commit 9e98092

Browse files
committed
test: add better routing table check
test: wait for provide to finish
1 parent 7e19612 commit 9e98092

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@
9090
"varint-decoder": "^0.4.0"
9191
},
9292
"pre-push": [
93-
"lint",
94-
"test"
93+
"lint"
9594
],
9695
"contributors": [
9796
"David Dias <[email protected]>",

test/bitswap.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
'use strict'
33

44
const { expect } = require('aegir/utils/chai')
5-
const delay = require('delay')
65
const PeerId = require('peer-id')
76
const sinon = require('sinon')
87
const pWaitFor = require('p-wait-for')
@@ -147,11 +146,9 @@ describe('bitswap with DHT', function () {
147146
// await dht routing table are updated
148147
await Promise.all([
149148
pWaitFor(() => nodes[0].libp2pNode._dht.routingTable.size >= 1),
150-
pWaitFor(() => nodes[1].libp2pNode._dht.routingTable.size >= 1)
149+
pWaitFor(() => nodes[1].libp2pNode._dht.routingTable.size >= 2),
150+
pWaitFor(() => nodes[2].libp2pNode._dht.routingTable.size >= 1)
151151
])
152-
153-
// Give time to process
154-
await delay(300)
155152
})
156153

157154
after(async () => {
@@ -164,10 +161,11 @@ describe('bitswap with DHT', function () {
164161

165162
it('put a block in 2, get it in 0', async () => {
166163
const block = await makeBlock()
164+
const provideSpy = sinon.spy(nodes[2].libp2pNode._dht, 'provide')
167165
await nodes[2].bitswap.put(block)
168166

169-
// Give put time to process
170-
await delay(300)
167+
// wait for the DHT to finish providing
168+
await provideSpy.returnValues[0]
171169

172170
const blockRetrieved = await nodes[0].bitswap.get(block.cid)
173171
expect(block.data).to.eql(blockRetrieved.data)

0 commit comments

Comments
 (0)