@@ -12,6 +12,7 @@ const PeerId = require('peer-id')
12
12
const PeerInfo = require ( 'peer-info' )
13
13
const duplexPair = require ( 'it-pair/duplex' )
14
14
const multiaddr = require ( 'multiaddr' )
15
+ const pWaitFor = require ( 'p-wait-for' )
15
16
16
17
const { codes : Errors } = require ( '../../src/errors' )
17
18
const { IdentifyService, multicodecs } = require ( '../../src/identify' )
@@ -203,16 +204,17 @@ describe('Identify', () => {
203
204
} )
204
205
205
206
sinon . spy ( libp2p . identifyService , 'identify' )
206
- sinon . spy ( libp2p . peerStore , 'replace' )
207
+ const peerStoreSpy = sinon . spy ( libp2p . peerStore , 'replace' )
207
208
208
209
const connection = await libp2p . dialer . connectToPeer ( remoteAddr )
209
210
expect ( connection ) . to . exist ( )
210
- // Wait for nextTick to trigger the identify call
211
- await delay ( 1 )
211
+
212
+ // Wait for peer store to be updated
213
+ await pWaitFor ( ( ) => peerStoreSpy . callCount === 1 )
212
214
expect ( libp2p . identifyService . identify . callCount ) . to . equal ( 1 )
213
- await libp2p . identifyService . identify . firstCall . returnValue
214
215
215
- expect ( libp2p . peerStore . replace . callCount ) . to . equal ( 1 )
216
+ // The connection should have no open streams
217
+ expect ( connection . streams ) . to . have . length ( 0 )
216
218
await connection . close ( )
217
219
} )
218
220
@@ -247,6 +249,9 @@ describe('Identify', () => {
247
249
const results = await call . returnValue
248
250
expect ( results . length ) . to . equal ( 1 )
249
251
}
252
+
253
+ // Verify the streams close
254
+ await pWaitFor ( ( ) => connection . streams . length === 0 )
250
255
} )
251
256
} )
252
257
} )
0 commit comments