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

Commit 501c304

Browse files
committed
Fix "not subscribed" errors in multi-node tests
1 parent 9beae1e commit 501c304

File tree

1 file changed

+64
-10
lines changed

1 file changed

+64
-10
lines changed

src/pubsub.js

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ module.exports = (common) => {
5555
return callback(err)
5656
}
5757

58-
console.log('->', peers)
5958
const hasAllPeers = peersToWait
6059
.map((e) => peers.includes(e))
6160
.filter((e) => e === false)
@@ -134,6 +133,18 @@ module.exports = (common) => {
134133
})
135134

136135
describe('.peers', () => {
136+
before((done) => {
137+
ipfs2.id((err, id) => {
138+
expect(err).to.not.exist
139+
const ipfs2Addr = id.addresses[0]
140+
ipfs1.swarm.connect(ipfs2Addr, (err) => {
141+
expect(err).to.not.exist
142+
// We need to fix this on libp2p level
143+
setTimeout(done, 3000)
144+
})
145+
})
146+
})
147+
137148
// TODO clarify what is the goal of pubsub.peers
138149
it('returns an error when not subscribed to a topic', (done) => {
139150
ipfs1.pubsub.peers(topic, (err, peers) => {
@@ -143,7 +154,7 @@ module.exports = (common) => {
143154
})
144155
})
145156

146-
it.skip('returns no peers within 10 seconds', (done) => {
157+
it('returns no peers within 10 seconds', (done) => {
147158
// Currently go-ipfs returns peers that have not been
148159
// subscribed to the topic. Enable when go-ipfs has been fixed
149160
ipfs1.pubsub.subscribe(topic, (err, subscription) => {
@@ -159,7 +170,7 @@ module.exports = (common) => {
159170
})
160171
})
161172

162-
it.skip('doesn\'t return extra peers', (done) => {
173+
it('doesn\'t return extra peers', (done) => {
163174
// Currently go-ipfs returns peers that have not been
164175
// subscribed to the topic. Enable when go-ipfs has been fixed
165176
ipfs1.pubsub.subscribe(topic, (err, subscription1) => {
@@ -182,10 +193,16 @@ module.exports = (common) => {
182193
})
183194
})
184195

185-
it.skip('returns peers for a topic - one peer', (done) => {
196+
it('returns peers for a topic - one peer', (done) => {
186197
// Currently go-ipfs returns peers that have not been subscribed to the topic
187198
// Enable when go-ipfs has been fixed
188199
const peersToWait = [ipfs2.peerId]
200+
let subscription2
201+
202+
ipfs1.pubsub.subscribe(topic, (err, subscription) => {
203+
expect(err).to.not.exist
204+
subscription2 = subscription
205+
})
189206

190207
ipfs2.pubsub.subscribe(topic, (err, subscription) => {
191208
expect(err).to.not.exist
@@ -197,8 +214,6 @@ module.exports = (common) => {
197214
done(err)
198215
}
199216

200-
console.log(peers)
201-
202217
const hasAllPeers = peersToWait
203218
.map((e) => peers.indexOf(e) !== -1)
204219
.filter((e) => e === false)
@@ -207,7 +222,9 @@ module.exports = (common) => {
207222
if (hasAllPeers) {
208223
clearInterval(i)
209224
expect(peers.length).to.equal(peersToWait.length)
210-
subscription.cancel(done)
225+
subscription.cancel()
226+
.then(() => subscription2.cancel())
227+
.then(done)
211228
}
212229
})
213230
}, 1000)
@@ -264,21 +281,30 @@ module.exports = (common) => {
264281
const ipfs2Addr = id.addresses[0]
265282
ipfs1.swarm.connect(ipfs2Addr, (err) => {
266283
expect(err).to.not.exist
284+
// We need to fix this on libp2p level
267285
setTimeout(done, 3000)
268286
})
269287
})
270288
})
271289

272290
it('receive messages from different node', (done) => {
273291
const expectedString = 'hello from the other side'
292+
let subscription2
293+
294+
ipfs2.pubsub.subscribe(topic, (err, subscription) => {
295+
expect(err).to.not.exist
296+
subscription2 = subscription
297+
})
274298

275299
ipfs1.pubsub.subscribe(topic, (err, subscription) => {
276300
expect(err).to.not.exist
277301
expect(subscription).to.exist
278302

279303
subscription.on('data', (d) => {
280304
expect(d.data).to.be.equal(expectedString)
281-
subscription.cancel(done)
305+
subscription.cancel()
306+
.then(() => subscription2.cancel())
307+
.then(done)
282308
})
283309

284310
waitForPeers(ipfs2, [ipfs1.peerId], (err) => {
@@ -293,6 +319,12 @@ module.exports = (common) => {
293319
it('receive multiple messages', (done) => {
294320
let receivedMessages = []
295321
const expectedMessages = 2
322+
let subscription2
323+
324+
ipfs2.pubsub.subscribe(topic, (err, subscription) => {
325+
expect(err).to.not.exist
326+
subscription2 = subscription
327+
})
296328

297329
ipfs1.pubsub.subscribe(topic, (err, subscription) => {
298330
expect(err).to.not.exists
@@ -303,7 +335,9 @@ module.exports = (common) => {
303335
receivedMessages.forEach((msg) => {
304336
expect(msg).to.be.equal('hi')
305337
})
306-
subscription.cancel(done)
338+
subscription.cancel()
339+
.then(() => subscription2.cancel())
340+
.then(done)
307341
}
308342
})
309343

@@ -317,12 +351,30 @@ module.exports = (common) => {
317351
})
318352

319353
describe('load tests', () => {
354+
before((done) => {
355+
ipfs2.id((err, id) => {
356+
expect(err).to.not.exist
357+
const ipfs2Addr = id.addresses[0]
358+
ipfs1.swarm.connect(ipfs2Addr, (err) => {
359+
expect(err).to.not.exist
360+
// We need to fix this on libp2p level
361+
setTimeout(done, 3000)
362+
})
363+
})
364+
})
365+
320366
it('send/receive 10k messages', (done) => {
321367
const expectedString = 'hello'
322368
const count = 10000
323369
let sendCount = 0
324370
let receivedCount = 0
325371
let startTime
372+
let subscription2
373+
374+
ipfs2.pubsub.subscribe(topic, (err, subscription) => {
375+
expect(err).to.not.exists
376+
subscription2 = subscription
377+
})
326378

327379
ipfs1.pubsub.subscribe(topic, (err, subscription) => {
328380
expect(err).to.not.exists
@@ -340,7 +392,9 @@ module.exports = (common) => {
340392
const duration = new Date().getTime() - startTime
341393
process.stdout.write(' \r')
342394
console.log(`Send/Receive 10k messages took: ${duration} ms, ${Math.floor(count / (duration / 1000))} ops / s`)
343-
subscription.cancel(done)
395+
subscription.cancel()
396+
.then(() => subscription2.cancel())
397+
.then(done)
344398
}
345399
})
346400

0 commit comments

Comments
 (0)