Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

fix: fix flaky pubsub test #3761

Merged
merged 1 commit into from
Jul 27, 2021
Merged
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
29 changes: 26 additions & 3 deletions packages/interface-ipfs-core/src/pubsub/unsubscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

const { isBrowser, isWebWorker, isElectronRenderer } = require('ipfs-utils/src/env')
const { getTopic } = require('./utils')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const { getDescribe, getIt } = require('../utils/mocha')
const waitFor = require('../utils/wait-for')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
Expand Down Expand Up @@ -40,7 +41,18 @@ module.exports = (common, options) => {
await ipfs.pubsub.unsubscribe(someTopic, handlers[i])
}

return expect(ipfs.pubsub.ls()).to.eventually.eql([])
// Unsubscribing in the http client aborts the connection we hold open
// but does not wait for it to close so the subscription list sometimes
// takes a little time to empty
await waitFor(async () => {
const subs = await ipfs.pubsub.ls()

return subs.length === 0
}, {
interval: 1000,
timeout: 30000,
name: 'subscriptions to be empty'
})
})

it(`should subscribe ${count} handlers and unsubscribe once with no reference to the handlers`, async () => {
Expand All @@ -50,7 +62,18 @@ module.exports = (common, options) => {
}
await ipfs.pubsub.unsubscribe(someTopic)

return expect(ipfs.pubsub.ls()).to.eventually.eql([])
// Unsubscribing in the http client aborts the connection we hold open
// but does not wait for it to close so the subscription list sometimes
// takes a little time to empty
await waitFor(async () => {
const subs = await ipfs.pubsub.ls()

return subs.length === 0
}, {
interval: 1000,
timeout: 30000,
name: 'subscriptions to be empty'
})
})
})
}