-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
child_process: allow promisified exec to be cancel #34249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
metcoder95
wants to merge
25
commits into
nodejs:master
from
metcoder95:cancel-promisified-child-process
+158
−26
Closed
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
eed3f17
child_process: allow promisified exec to be cancel
metcoder95 0ef841d
child_process: fix validation issue
metcoder95 70cb86c
child_process: use Primordials instead of plain Promise
metcoder95 a6ae623
child_process: refactor according to review
metcoder95 988ea3f
child_process: remove license from test
metcoder95 78e7521
child_process: improve testing
metcoder95 c8210f6
child_process: fix linter issues
metcoder95 3dca212
child_process: check if AbortSignal is aborted before rejecting/resol…
metcoder95 4163c44
child_process: check for signal before looking is aborted
metcoder95 9e3291e
child_process: refactor signal to use spawn function
metcoder95 3b14ebe
child_process: fix linter issues
metcoder95 087f924
child_process: revert check for extra callback
metcoder95 0fd0719
child_process: fix double AbortError emit
metcoder95 a41ac9a
child_process: fix linter issues
metcoder95 f9af3fd
child_process: fix fork issue with AbortController
metcoder95 2b19cd5
child_process: remove whitespace
metcoder95 f642015
child_process: re-order alphabetically the options
metcoder95 dade71b
child_process: refactor spawnWithSignal
metcoder95 5e7aa7d
child_process: remove wrapper function
metcoder95 2305734
child_process: revert refactor to spawn
metcoder95 a60b935
child_process: fix tests
metcoder95 fe077b0
child_process: refactor
metcoder95 72ff68a
child_process: refactor tests
metcoder95 026021a
child_process: refactor listeners args
metcoder95 c093035
child_process: inline listener
metcoder95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
51 changes: 51 additions & 0 deletions
51
test/parallel/test-child-process-exec-abortcontroller-promisified.js
This file contains hidden or 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,51 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const exec = require('child_process').exec; | ||
const { promisify } = require('util'); | ||
|
||
let pwdcommand, dir; | ||
const execPromisifed = promisify(exec); | ||
const invalidArgTypeError = { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
name: 'TypeError' | ||
}; | ||
|
||
|
||
if (common.isWindows) { | ||
pwdcommand = 'echo %cd%'; | ||
dir = 'c:\\windows'; | ||
} else { | ||
pwdcommand = 'pwd'; | ||
dir = '/dev'; | ||
} | ||
|
||
|
||
{ | ||
const ac = new AbortController(); | ||
const signal = ac.signal; | ||
const promise = execPromisifed(pwdcommand, { cwd: dir, signal }); | ||
assert.rejects(promise, /AbortError/).then(common.mustCall()); | ||
ac.abort(); | ||
} | ||
|
||
{ | ||
assert.throws(() => { | ||
execPromisifed(pwdcommand, { cwd: dir, signal: {} }); | ||
}, invalidArgTypeError); | ||
} | ||
|
||
{ | ||
function signal() {} | ||
assert.throws(() => { | ||
execPromisifed(pwdcommand, { cwd: dir, signal }); | ||
}, invalidArgTypeError); | ||
} | ||
|
||
{ | ||
const ac = new AbortController(); | ||
const signal = (ac.abort(), ac.signal); | ||
const promise = execPromisifed(pwdcommand, { cwd: dir, signal }); | ||
|
||
assert.rejects(promise, /AbortError/).then(common.mustCall()); | ||
} |
58 changes: 58 additions & 0 deletions
58
test/parallel/test-child-process-execFile-promisified-abortController.js
This file contains hidden or 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,58 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { promisify } = require('util'); | ||
const execFile = require('child_process').execFile; | ||
const fixtures = require('../common/fixtures'); | ||
|
||
const echoFixture = fixtures.path('echo.js'); | ||
const promisified = promisify(execFile); | ||
const invalidArgTypeError = { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
name: 'TypeError' | ||
}; | ||
|
||
{ | ||
// Verify that the signal option works properly | ||
const ac = new AbortController(); | ||
const signal = ac.signal; | ||
const promise = promisified(process.execPath, [echoFixture, 0], { signal }); | ||
|
||
ac.abort(); | ||
|
||
assert.rejects( | ||
promise, | ||
{ name: 'AbortError' } | ||
).then(common.mustCall()); | ||
} | ||
|
||
{ | ||
// Verify that the signal option works properly when already aborted | ||
const ac = new AbortController(); | ||
const { signal } = ac; | ||
ac.abort(); | ||
|
||
assert.rejects( | ||
promisified(process.execPath, [echoFixture, 0], { signal }), | ||
{ name: 'AbortError' } | ||
).then(common.mustCall()); | ||
} | ||
|
||
{ | ||
// Verify that if something different than Abortcontroller.signal | ||
// is passed, ERR_INVALID_ARG_TYPE is thrown | ||
const signal = {}; | ||
assert.throws(() => { | ||
promisified(process.execPath, [echoFixture, 0], { signal }); | ||
}, invalidArgTypeError); | ||
} | ||
|
||
{ | ||
// Verify that if something different than Abortcontroller.signal | ||
// is passed, ERR_INVALID_ARG_TYPE is thrown | ||
const signal = 'world!'; | ||
assert.throws(() => { | ||
promisified(process.execPath, [echoFixture, 0], { signal }); | ||
}, invalidArgTypeError); | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.