This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathunsubscribe.js
61 lines (52 loc) · 1.64 KB
/
unsubscribe.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* eslint-env mocha */
'use strict'
const eachSeries = require('async/each')
const timesSeries = require('async/timesSeries')
const { getTopic } = require('./utils')
const { getDescribe, getIt, expect } = require('../utils/mocha')
module.exports = (createCommon, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()
describe('.pubsub.unsubscribe', function () {
this.timeout(80 * 1000)
let ipfs
before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)
common.setup((err, factory) => {
expect(err).to.not.exist()
factory.spawnNode((err, node) => {
expect(err).to.not.exist()
ipfs = node
done()
})
})
})
after((done) => common.teardown(done))
it('should subscribe and unsubscribe 10 times', (done) => {
const count = 10
const someTopic = getTopic()
timesSeries(count, (_, cb) => {
const handler = (msg) => {}
ipfs.pubsub.subscribe(someTopic, handler, (err) => cb(err, handler))
}, (err, handlers) => {
expect(err).to.not.exist()
eachSeries(
handlers,
(handler, cb) => ipfs.pubsub.unsubscribe(someTopic, handler, cb),
(err) => {
expect(err).to.not.exist()
// Assert unsubscribe worked
ipfs.pubsub.ls((err, topics) => {
expect(err).to.not.exist()
expect(topics).to.eql([])
done()
})
}
)
})
})
})
}