Skip to content

Commit c537140

Browse files
committed
test: improve deterministic browser tests
test: remove unneeded test timeout
1 parent 3b7c4b5 commit c537140

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

test/transports.browser.js

+20-14
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ describe('transports', () => {
198198
let peer2
199199
let node1
200200
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+
})
201210

202211
it('create two peerInfo with webrtc-star addrs', (done) => {
203212
parallel([
@@ -270,30 +279,27 @@ describe('transports', () => {
270279
})
271280
})
272281

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()
275285

276-
let counter = 0
286+
const b58Id = id3.toB58String()
277287

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+
}
283293
}
284-
}
285-
286-
PeerId.create({ bits: 512 }, (err, id3) => {
287-
expect(err).to.not.exist()
288294

289295
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
291297
peer3.multiaddrs.add(ma3)
292298

293299
node1.on('peer:discovery', (peerInfo) => node1.dial(peerInfo, check))
294300
node2.on('peer:discovery', (peerInfo) => node2.dial(peerInfo, check))
295301

296-
const node3 = new Node({
302+
node3 = new Node({
297303
peerInfo: peer3
298304
})
299305
node3.start(check)

0 commit comments

Comments
 (0)