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

fix: fix pubsub subscribe with multiple node in firefox #571

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 39 additions & 20 deletions src/pubsub/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = (common, options) => {
const it = getIt(options)

describe('.pubsub.subscribe', function () {
this.timeout(80 * 1000)
this.timeout(20 * 1000)

let ipfs1
let ipfs2
Expand All @@ -26,8 +26,6 @@ module.exports = (common, options) => {

before(async () => {
ipfs1 = (await common.spawn()).api
// TODO 'multiple connected nodes' tests fails with go in Firefox
// and JS is flaky everywhere
ipfs2 = (await common.spawn({ type: 'go' })).api
})

Expand Down Expand Up @@ -164,12 +162,18 @@ module.exports = (common, options) => {
const msgStream2 = pushable()

const sub1 = msg => {
msgStream1.push(msg)
msgStream1.end()
// Support firefox https://github.com/ipfs/js-ipfs-http-client/blob/master/src/pubsub/subscribe.js#L27-L37
if (msg.data.length !== 0) {
msgStream1.push(msg)
msgStream1.end()
}
}
const sub2 = msg => {
msgStream2.push(msg)
msgStream2.end()
// Support firefox https://github.com/ipfs/js-ipfs-http-client/blob/master/src/pubsub/subscribe.js#L27-L37
if (msg.data.length !== 0) {
msgStream2.push(msg)
msgStream2.end()
}
}

await Promise.all([
Expand Down Expand Up @@ -198,12 +202,18 @@ module.exports = (common, options) => {
const msgStream2 = pushable()

const sub1 = msg => {
msgStream1.push(msg)
msgStream1.end()
// Support firefox https://github.com/ipfs/js-ipfs-http-client/blob/master/src/pubsub/subscribe.js#L27-L37
if (msg.data.length !== 0) {
msgStream1.push(msg)
msgStream1.end()
}
}
const sub2 = msg => {
msgStream2.push(msg)
msgStream2.end()
// Support firefox https://github.com/ipfs/js-ipfs-http-client/blob/master/src/pubsub/subscribe.js#L27-L37
if (msg.data.length !== 0) {
msgStream2.push(msg)
msgStream2.end()
}
}

await Promise.all([
Expand Down Expand Up @@ -231,16 +241,22 @@ module.exports = (common, options) => {
const msgStream2 = pushable()

const sub1 = msg => {
msgStream1.push(msg)
sub1.called++
if (sub1.called === outbox.length) msgStream1.end()
// Support firefox https://github.com/ipfs/js-ipfs-http-client/blob/master/src/pubsub/subscribe.js#L27-L37
if (msg.data.length !== 0) {
msgStream1.push(msg)
sub1.called++
if (sub1.called === outbox.length) msgStream1.end()
}
}
sub1.called = 0

const sub2 = msg => {
msgStream2.push(msg)
sub2.called++
if (sub2.called === outbox.length) msgStream2.end()
// Support firefox https://github.com/ipfs/js-ipfs-http-client/blob/master/src/pubsub/subscribe.js#L27-L37
if (msg.data.length !== 0) {
msgStream2.push(msg)
sub2.called++
if (sub2.called === outbox.length) msgStream2.end()
}
}
sub2.called = 0

Expand Down Expand Up @@ -272,9 +288,12 @@ module.exports = (common, options) => {
const msgStream = pushable()

const sub = msg => {
msgStream.push(msg)
sub.called++
if (sub.called === count) msgStream.end()
// Support firefox https://github.com/ipfs/js-ipfs-http-client/blob/master/src/pubsub/subscribe.js#L27-L37
if (msg.data.length !== 0) {
msgStream.push(msg)
sub.called++
if (sub.called === count) msgStream.end()
}
}
sub.called = 0

Expand Down