Skip to content
This repository was archived by the owner on Apr 29, 2020. It is now read-only.

Commit 51346e2

Browse files
committed
fix(tests): too fast
1 parent 2d7e8e7 commit 51346e2

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

test/webrtc-star-only.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const pull = require('pull-stream')
1010

1111
const Node = require('../src')
1212

13-
describe('libp2p-ipfs-browser (webrtc only)', function () {
14-
this.timeout(15 * 1000)
15-
13+
describe('libp2p-ipfs-browser (webrtc only)', () => {
1614
let peer1
1715
let peer2
1816
let node1
@@ -104,28 +102,28 @@ describe('libp2p-ipfs-browser (webrtc only)', function () {
104102
})
105103

106104
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+
107115
PeerId.create((err, id3) => {
108116
expect(err).to.not.exist
109117

110118
const peer3 = new PeerInfo(id3)
111119
const mh3 = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/' + id3.toB58String())
112120
peer3.multiaddr.add(mh3)
113121

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))
120124

121125
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)
129127
})
130128
})
131129
})

0 commit comments

Comments
 (0)