Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit cfa0c63

Browse files
JGAntunesalanshaw
authored andcommitted
fix(ping): peers setup is not dependent on an artificial delay
1 parent 938e431 commit cfa0c63

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

test/core/ping.spec.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,28 @@ describe('ping', function () {
170170

171171
// Connect the nodes
172172
before(function (done) {
173-
this.timeout(60 * 1000)
173+
this.timeout(30 * 1000)
174+
let interval
175+
176+
// Check to see if peers are already connected
177+
const checkConnections = () => {
178+
ipfsdB.api.swarm.peers((err, peerInfos) => {
179+
if (err) return done(err)
180+
181+
if (peerInfos.length > 1) {
182+
clearInterval(interval)
183+
return done()
184+
}
185+
})
186+
}
174187

175188
parallel([
176189
ipfsdA.api.swarm.connect.bind(ipfsdA.api, bMultiaddr),
177190
ipfsdB.api.swarm.connect.bind(ipfsdB.api, cMultiaddr)
178-
], (err) => setTimeout(() => done(err), 500)) // FIXME timeout needed for connections to succeed
191+
], (err) => {
192+
if (err) return done(err)
193+
interval = setInterval(checkConnections, 300)
194+
})
179195
})
180196

181197
after((done) => ipfsdA.stop(done))

0 commit comments

Comments
 (0)