@@ -10,9 +10,7 @@ const pull = require('pull-stream')
10
10
11
11
const Node = require ( '../src' )
12
12
13
- describe ( 'libp2p-ipfs-browser (webrtc only)' , function ( ) {
14
- this . timeout ( 15 * 1000 )
15
-
13
+ describe ( 'libp2p-ipfs-browser (webrtc only)' , ( ) => {
16
14
let peer1
17
15
let peer2
18
16
let node1
@@ -104,28 +102,28 @@ describe('libp2p-ipfs-browser (webrtc only)', function () {
104
102
} )
105
103
106
104
it ( 'create a third node and check that discovery works' , ( done ) => {
105
+ let counter = 0
106
+
107
+ function check ( ) {
108
+ if ( ++ counter === 3 ) {
109
+ expect ( Object . keys ( node1 . swarm . muxedConns ) . length ) . to . equal ( 1 )
110
+ expect ( Object . keys ( node2 . swarm . muxedConns ) . length ) . to . equal ( 1 )
111
+ done ( )
112
+ }
113
+ }
114
+
107
115
PeerId . create ( ( err , id3 ) => {
108
116
expect ( err ) . to . not . exist
109
117
110
118
const peer3 = new PeerInfo ( id3 )
111
119
const mh3 = multiaddr ( '/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/' + id3 . toB58String ( ) )
112
120
peer3 . multiaddr . add ( mh3 )
113
121
114
- node1 . discovery . on ( 'peer' , ( peerInfo ) => {
115
- node1 . dialByPeerInfo ( peerInfo , ( ) => { } )
116
- } )
117
- node2 . discovery . on ( 'peer' , ( peerInfo ) => {
118
- node2 . dialByPeerInfo ( peerInfo , ( ) => { } )
119
- } )
122
+ node1 . discovery . on ( 'peer' , ( peerInfo ) => node1 . dialByPeerInfo ( peerInfo , check ) )
123
+ node2 . discovery . on ( 'peer' , ( peerInfo ) => node2 . dialByPeerInfo ( peerInfo , check ) )
120
124
121
125
const node3 = new Node ( peer3 )
122
- node3 . start ( ( ) => {
123
- setTimeout ( ( ) => {
124
- expect ( Object . keys ( node1 . swarm . muxedConns ) . length ) . to . equal ( 1 )
125
- expect ( Object . keys ( node2 . swarm . muxedConns ) . length ) . to . equal ( 1 )
126
- done ( )
127
- } , 2000 )
128
- } )
126
+ node3 . start ( check )
129
127
} )
130
128
} )
131
129
} )
0 commit comments