-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes: #37220 Refs: #36607 PR-URL: #46494 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
- Loading branch information
1 parent
4d36ebd
commit 6d584ae
Showing
4 changed files
with
136 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Flags: --expose-gc | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const { aborted } = require('util'); | ||
const assert = require('assert'); | ||
const { getEventListeners } = require('events'); | ||
const { spawn } = require('child_process'); | ||
|
||
{ | ||
// Test aborted works when provided a resource | ||
const ac = new AbortController(); | ||
aborted(ac.signal, {}).then(common.mustCall()); | ||
ac.abort(); | ||
assert.strictEqual(ac.signal.aborted, true); | ||
assert.strictEqual(getEventListeners(ac.signal, 'abort').length, 0); | ||
} | ||
|
||
{ | ||
// Test aborted with gc cleanup | ||
const ac = new AbortController(); | ||
aborted(ac.signal, {}).then(common.mustNotCall()); | ||
setImmediate(() => { | ||
global.gc(); | ||
ac.abort(); | ||
assert.strictEqual(ac.signal.aborted, true); | ||
assert.strictEqual(getEventListeners(ac.signal, 'abort').length, 0); | ||
}); | ||
} | ||
|
||
{ | ||
// Fails with error if not provided abort signal | ||
Promise.all([{}, null, undefined, Symbol(), [], 1, 0, 1n, true, false, 'a', () => {}].map((sig) => | ||
assert.rejects(aborted(sig, {}), { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
}) | ||
)).then(common.mustCall()); | ||
} | ||
|
||
{ | ||
// Fails if not provided a resource | ||
const ac = new AbortController(); | ||
Promise.all([null, undefined, 0, 1, 0n, 1n, Symbol(), '', 'a'].map((resource) => | ||
assert.rejects(aborted(ac.signal, resource), { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
}) | ||
)).then(common.mustCall()); | ||
} | ||
|
||
{ | ||
const childProcess = spawn(process.execPath, ['--input-type=module']); | ||
childProcess.on('exit', common.mustCall((code) => { | ||
assert.strictEqual(code, 13); | ||
})); | ||
childProcess.stdin.end(` | ||
import { aborted } from 'node:util'; | ||
await aborted(new AbortController().signal, {}); | ||
`); | ||
} |