22'use strict'
33
44const { expect } = require ( 'aegir/utils/chai' )
5- const delay = require ( 'delay' )
65const PeerId = require ( 'peer-id' )
76const sinon = require ( 'sinon' )
87const 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