|
1 | 1 | /* eslint-env mocha */
|
2 | 2 | 'use strict'
|
3 | 3 |
|
4 |
| -const eachSeries = require('async/eachSeries') |
5 |
| -const timesSeries = require('async/timesSeries') |
| 4 | +const { isBrowser, isWebWorker } = require('ipfs-utils/src/env') |
6 | 5 | const { getTopic } = require('./utils')
|
7 | 6 | const { getDescribe, getIt, expect } = require('../utils/mocha')
|
8 | 7 |
|
@@ -33,33 +32,26 @@ module.exports = (createCommon, options) => {
|
33 | 32 |
|
34 | 33 | after((done) => common.teardown(done))
|
35 | 34 |
|
36 |
| - it('should subscribe and unsubscribe 10 times', (done) => { |
37 |
| - const count = 10 |
| 35 | + // Browser/worker has max ~6 open HTTP requests to the same origin |
| 36 | + const count = isBrowser || isWebWorker ? 6 : 10 |
| 37 | + |
| 38 | + it(`should subscribe and unsubscribe ${count} times`, async () => { |
38 | 39 | const someTopic = getTopic()
|
| 40 | + const handlers = Array.from(Array(count), () => msg => {}) |
39 | 41 |
|
40 |
| - timesSeries(count, (_, cb) => { |
41 |
| - const handler = (msg) => {} |
42 |
| - ipfs.pubsub.subscribe(someTopic, handler, (err) => cb(err, handler)) |
43 |
| - }, (err, handlers) => { |
44 |
| - expect(err).to.not.exist() |
45 |
| - eachSeries( |
46 |
| - handlers, |
47 |
| - (handler, cb) => ipfs.pubsub.unsubscribe(someTopic, handler, cb), |
48 |
| - (err) => { |
49 |
| - expect(err).to.not.exist() |
50 |
| - // Assert unsubscribe worked |
51 |
| - ipfs.pubsub.ls((err, topics) => { |
52 |
| - expect(err).to.not.exist() |
53 |
| - expect(topics).to.eql([]) |
54 |
| - done() |
55 |
| - }) |
56 |
| - } |
57 |
| - ) |
58 |
| - }) |
| 42 | + for (let i = 0; i < count; i++) { |
| 43 | + await ipfs.pubsub.subscribe(someTopic, handlers[i]) |
| 44 | + } |
| 45 | + |
| 46 | + for (let i = 0; i < count; i++) { |
| 47 | + await ipfs.pubsub.unsubscribe(someTopic, handlers[i]) |
| 48 | + } |
| 49 | + |
| 50 | + const topics = await ipfs.pubsub.ls() |
| 51 | + expect(topics).to.eql([]) |
59 | 52 | })
|
60 | 53 |
|
61 |
| - it('should subscribe 10 handlers and unsunscribe once with no reference to the handlers', async () => { |
62 |
| - const count = 10 |
| 54 | + it(`should subscribe ${count} handlers and unsunscribe once with no reference to the handlers`, async () => { |
63 | 55 | const someTopic = getTopic()
|
64 | 56 | for (let i = 0; i < count; i++) {
|
65 | 57 | await ipfs.pubsub.subscribe(someTopic, (msg) => {})
|
|
0 commit comments