2
2
'use strict'
3
3
4
4
const { expect } = require ( 'aegir/utils/chai' )
5
- const delay = require ( 'delay' )
6
5
const PeerId = require ( 'peer-id' )
7
6
const sinon = require ( 'sinon' )
8
7
const pWaitFor = require ( 'p-wait-for' )
@@ -147,11 +146,9 @@ describe('bitswap with DHT', function () {
147
146
// await dht routing table are updated
148
147
await Promise . all ( [
149
148
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 )
151
151
] )
152
-
153
- // Give time to process
154
- await delay ( 300 )
155
152
} )
156
153
157
154
after ( async ( ) => {
@@ -164,10 +161,11 @@ describe('bitswap with DHT', function () {
164
161
165
162
it ( 'put a block in 2, get it in 0' , async ( ) => {
166
163
const block = await makeBlock ( )
164
+ const provideSpy = sinon . spy ( nodes [ 2 ] . libp2pNode . _dht , 'provide' )
167
165
await nodes [ 2 ] . bitswap . put ( block )
168
166
169
- // Give put time to process
170
- await delay ( 300 )
167
+ // wait for the DHT to finish providing
168
+ await provideSpy . returnValues [ 0 ]
171
169
172
170
const blockRetrieved = await nodes [ 0 ] . bitswap . get ( block . cid )
173
171
expect ( block . data ) . to . eql ( blockRetrieved . data )
0 commit comments