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

Commit 2019c45

Browse files
committed
fix: many fixes for pubsub tests with new async unsubscribe
License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent f798597 commit 2019c45

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

js/src/pubsub.js

+34-31
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function makeCheck (n, done) {
6363
}
6464

6565
module.exports = (common) => {
66-
describe('.pubsub', function () {
66+
describe.only('.pubsub', function () {
6767
this.timeout(80 * 1000)
6868

6969
const getTopic = () => 'pubsub-tests-' + hat()
@@ -205,7 +205,7 @@ module.exports = (common) => {
205205
}
206206

207207
ipfs1.pubsub
208-
.subscribe(topic, {}, handler)
208+
.subscribe(topic, handler, {})
209209
.then(() => ipfs1.pubsub.publish(topic, Buffer.from('hi'), check))
210210
.catch((err) => expect(err).to.not.exist())
211211
})
@@ -218,17 +218,17 @@ module.exports = (common) => {
218218
expect(msg.data.toString()).to.eql('hello')
219219

220220
series([
221-
(cb) => ipfs1.pubsub.unsubscribe(topic, handler1, cb)
221+
(cb) => ipfs1.pubsub.unsubscribe(topic, handler1, cb),
222222
(cb) => ipfs1.pubsub.ls(cb),
223223
(cb) => ipfs1.pubsub.unsubscribe(topic, handler2, cb),
224224
(cb) => ipfs1.pubsub.ls(cb)
225225
], (err, res) => {
226226
expect(err).to.not.exist()
227227

228228
// Still subscribed as there is one listener left
229-
expect(res[0]).to.eql([topic])
229+
expect(res[1]).to.eql([topic])
230230
// Now all listeners are gone no subscription anymore
231-
expect(res[2]).to.eql([])
231+
expect(res[3]).to.eql([])
232232
check()
233233
})
234234
}
@@ -310,12 +310,13 @@ module.exports = (common) => {
310310

311311
ipfs1.pubsub.peers(topic, (err, peers) => {
312312
expect(err).to.not.exist()
313-
314313
expect(peers).to.be.empty()
315-
ipfs1.pubsub.unsubscribe(topic, sub1)
316-
ipfs2.pubsub.unsubscribe(topicOther, sub2)
317-
ipfs3.pubsub.unsubscribe(topicOther, sub3)
318-
done()
314+
315+
parallel([
316+
(cb) => ipfs1.pubsub.unsubscribe(topic, sub1, cb),
317+
(cb) => ipfs2.pubsub.unsubscribe(topicOther, sub2, cb),
318+
(cb) => ipfs3.pubsub.unsubscribe(topicOther, sub3, cb)
319+
], done)
319320
})
320321
})
321322
})
@@ -335,11 +336,12 @@ module.exports = (common) => {
335336
(cb) => waitForPeers(ipfs1, topic, [ipfs2.peerId.id], cb)
336337
], (err) => {
337338
expect(err).to.not.exist()
338-
ipfs1.pubsub.unsubscribe(topic, sub1)
339-
ipfs2.pubsub.unsubscribe(topic, sub2)
340-
ipfs3.pubsub.unsubscribe(topic, sub3)
341339

342-
done()
340+
parallel([
341+
(cb) => ipfs1.pubsub.unsubscribe(topic, sub1, cb),
342+
(cb) => ipfs2.pubsub.unsubscribe(topic, sub2, cb),
343+
(cb) => ipfs3.pubsub.unsubscribe(topic, sub3, cb)
344+
], done)
343345
})
344346
})
345347

@@ -359,11 +361,12 @@ module.exports = (common) => {
359361
], cb)
360362
], (err) => {
361363
expect(err).to.not.exist()
362-
ipfs1.pubsub.unsubscribe(topic, sub1)
363-
ipfs2.pubsub.unsubscribe(topic, sub2)
364-
ipfs3.pubsub.unsubscribe(topic, sub3)
365364

366-
done()
365+
parallel([
366+
(cb) => ipfs1.pubsub.unsubscribe(topic, sub1, cb),
367+
(cb) => ipfs2.pubsub.unsubscribe(topic, sub2, cb),
368+
(cb) => ipfs3.pubsub.unsubscribe(topic, sub3, cb)
369+
], done)
367370
})
368371
})
369372
})
@@ -415,11 +418,9 @@ module.exports = (common) => {
415418
expect(list.sort())
416419
.to.eql(topics.map((t) => t.name).sort())
417420

418-
topics.forEach((t) => {
419-
ipfs1.pubsub.unsubscribe(t.name, t.handler)
420-
})
421-
422-
done()
421+
parallel(topics.map((t) => {
422+
return (cb) => ipfs1.pubsub.unsubscribe(t.name, t.handler, cb)
423+
}), done)
423424
})
424425
})
425426
})
@@ -436,8 +437,8 @@ module.exports = (common) => {
436437

437438
afterEach((done) => {
438439
parallel([
439-
(cb) => ipfs1.pubsub.unsubscribe(topic, sub1, cb)
440-
(cb) => ipfs2.pubsub.unsubscribe(topic, sub2, cb)
440+
(cb) => ipfs1.pubsub.unsubscribe(topic, sub1, cb),
441+
(cb) => ipfs2.pubsub.unsubscribe(topic, sub2, cb)
441442
], done)
442443
})
443444

@@ -589,9 +590,11 @@ module.exports = (common) => {
589590
topic = getTopic()
590591
})
591592

592-
afterEach(() => {
593-
ipfs1.pubsub.unsubscribe(topic, sub1)
594-
ipfs2.pubsub.unsubscribe(topic, sub2)
593+
afterEach((done) => {
594+
parallel([
595+
(cb) => ipfs1.pubsub.unsubscribe(topic, sub1, cb),
596+
(cb) => ipfs2.pubsub.unsubscribe(topic, sub2, cb)
597+
], done)
595598
})
596599

597600
it('send/receive 10k messages', function (done) {
@@ -672,16 +675,16 @@ module.exports = (common) => {
672675
expect(err).to.not.exist()
673676
each(
674677
handlers,
675-
(handler, cb) => ipfs1.pubsub.unsubscribe(someTopic, handler, cb)
678+
(handler, cb) => ipfs1.pubsub.unsubscribe(someTopic, handler, cb),
676679
(err) => {
677680
expect(err).to.not.exist()
678681
ipfs1.pubsub.ls((err, topics) => {
679682
expect(err).to.not.exist()
680683
expect(topics).to.eql([])
681684
done()
682685
})
683-
})
684-
})
686+
}
687+
)
685688
}
686689
)
687690
})

0 commit comments

Comments
 (0)