@@ -198,6 +198,15 @@ describe('transports', () => {
198
198
let peer2
199
199
let node1
200
200
let node2
201
+ let node3
202
+
203
+ after ( ( done ) => {
204
+ parallel ( [
205
+ ( cb ) => node1 . stop ( cb ) ,
206
+ ( cb ) => node2 . stop ( cb ) ,
207
+ ( cb ) => node3 . stop ( cb )
208
+ ] , done )
209
+ } )
201
210
202
211
it ( 'create two peerInfo with webrtc-star addrs' , ( done ) => {
203
212
parallel ( [
@@ -270,30 +279,27 @@ describe('transports', () => {
270
279
} )
271
280
} )
272
281
273
- it ( 'create a third node and check that discovery works' , function ( done ) {
274
- this . timeout ( 60 * 1000 )
282
+ it ( 'create a third node and check that discovery works' , ( done ) => {
283
+ PeerId . create ( { bits : 512 } , ( err , id3 ) => {
284
+ expect ( err ) . to . not . exist ( )
275
285
276
- let counter = 0
286
+ const b58Id = id3 . toB58String ( )
277
287
278
- function check ( ) {
279
- if ( ++ counter === 3 ) {
280
- expect ( Object . keys ( node1 . _switch . muxedConns ) . length ) . to . equal ( 1 )
281
- expect ( Object . keys ( node2 . _switch . muxedConns ) . length ) . to . equal ( 1 )
282
- done ( )
288
+ function check ( ) {
289
+ // Verify both nodes are connected to node 3
290
+ if ( node1 . _switch . muxedConns [ b58Id ] && node2 . _switch . muxedConns [ b58Id ] ) {
291
+ done ( )
292
+ }
283
293
}
284
- }
285
-
286
- PeerId . create ( { bits : 512 } , ( err , id3 ) => {
287
- expect ( err ) . to . not . exist ( )
288
294
289
295
const peer3 = new PeerInfo ( id3 )
290
- const ma3 = '/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/ipfs/' + id3 . toB58String ( )
296
+ const ma3 = '/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/ipfs/' + b58Id
291
297
peer3 . multiaddrs . add ( ma3 )
292
298
293
299
node1 . on ( 'peer:discovery' , ( peerInfo ) => node1 . dial ( peerInfo , check ) )
294
300
node2 . on ( 'peer:discovery' , ( peerInfo ) => node2 . dial ( peerInfo , check ) )
295
301
296
- const node3 = new Node ( {
302
+ node3 = new Node ( {
297
303
peerInfo : peer3
298
304
} )
299
305
node3 . start ( check )
0 commit comments