This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: stalling subscription on (node) http-client when daemon is stopp…
…ed (#3468) This change fixes #3465 by upgrading to a temporary fork of node-fetch with node-fetch/node-fetch#1172 applied. Co-authored-by: achingbrain <alex@achingbrain.net>
- Loading branch information
1 parent
e294067
commit 0266abf
Showing
11 changed files
with
120 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const { expect } = require('aegir/utils/chai') | ||
const { AbortController } = require('native-abort-controller') | ||
|
||
const f = require('./utils/factory')() | ||
|
||
describe('.pubsub', function () { | ||
this.timeout(20 * 1000) | ||
describe('.subscribe', () => { | ||
let ipfs | ||
let ctl | ||
|
||
beforeEach(async function () { | ||
this.timeout(30 * 1000) // slow CI | ||
|
||
ctl = await await f.spawn({ | ||
args: '--enable-pubsub-experiment' | ||
}) | ||
|
||
ipfs = ctl.api | ||
}) | ||
|
||
afterEach(() => f.clean()) | ||
|
||
it('.onError when connection is closed', async () => { | ||
const topic = 'gossipboom' | ||
let messageCount = 0 | ||
let onError | ||
const error = new Promise(resolve => { onError = resolve }) | ||
|
||
await ipfs.pubsub.subscribe(topic, message => { | ||
messageCount++ | ||
|
||
if (messageCount === 2) { | ||
// Stop the daemon | ||
ctl.stop().catch() | ||
} | ||
}, { | ||
onError | ||
}) | ||
|
||
await ipfs.pubsub.publish(topic, 'hello') | ||
await ipfs.pubsub.publish(topic, 'bye') | ||
|
||
await expect(error).to.eventually.be.fulfilled().and.to.be.instanceOf(Error) | ||
}) | ||
|
||
it('does not call onError when aborted', async () => { | ||
const controller = new AbortController() | ||
const topic = 'gossipabort' | ||
const messages = [] | ||
let onError | ||
let onReceived | ||
|
||
const received = new Promise(resolve => { onReceived = resolve }) | ||
const error = new Promise(resolve => { onError = resolve }) | ||
|
||
await ipfs.pubsub.subscribe(topic, message => { | ||
messages.push(message) | ||
if (messages.length === 2) { | ||
onReceived() | ||
} | ||
}, { | ||
onError, | ||
signal: controller.signal | ||
}) | ||
|
||
await ipfs.pubsub.publish(topic, 'hello') | ||
await ipfs.pubsub.publish(topic, 'bye') | ||
|
||
await received | ||
controller.abort() | ||
|
||
// Stop the daemon | ||
await ctl.stop() | ||
// Just to make sure no error is caused by above line | ||
setTimeout(onError, 200, 'aborted') | ||
|
||
await expect(error).to.eventually.be.fulfilled().and.to.equal('aborted') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters