Skip to content

Commit

Permalink
test: add better routing table check
Browse files Browse the repository at this point in the history
test: wait for provide to finish
  • Loading branch information
jacobheun authored and vasco-santos committed May 28, 2020
1 parent ec3aa81 commit a2114fa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@
"varint-decoder": "^0.4.0"
},
"pre-push": [
"lint",
"test"
"lint"
],
"contributors": [
"David Dias <[email protected]>",
Expand Down
12 changes: 5 additions & 7 deletions test/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
'use strict'

const { expect } = require('aegir/utils/chai')
const delay = require('delay')
const PeerId = require('peer-id')
const sinon = require('sinon')
const pWaitFor = require('p-wait-for')
Expand Down Expand Up @@ -147,11 +146,9 @@ describe('bitswap with DHT', function () {
// await dht routing table are updated
await Promise.all([
pWaitFor(() => nodes[0].libp2pNode._dht.routingTable.size >= 1),
pWaitFor(() => nodes[1].libp2pNode._dht.routingTable.size >= 1)
pWaitFor(() => nodes[1].libp2pNode._dht.routingTable.size >= 2),
pWaitFor(() => nodes[2].libp2pNode._dht.routingTable.size >= 1)
])

// Give time to process
await delay(300)
})

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

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

// Give put time to process
await delay(300)
// wait for the DHT to finish providing
await provideSpy.returnValues[0]

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

0 comments on commit a2114fa

Please sign in to comment.