mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
test: remove common.disableCrashOnUnhandledRejection
Use the --unhandled-rejections=none CLI flag instead. PR-URL: https://github.com/nodejs/node/pull/38210 Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
3377eb9641
commit
05df701e70
|
|
@ -250,11 +250,9 @@ countdown.dec(); // The countdown callback will be invoked now.
|
||||||
|
|
||||||
When writing tests involving promises, it is generally good to wrap the
|
When writing tests involving promises, it is generally good to wrap the
|
||||||
`onFulfilled` handler, otherwise the test could successfully finish if the
|
`onFulfilled` handler, otherwise the test could successfully finish if the
|
||||||
promise never resolves (pending promises do not keep the event loop alive). The
|
promise never resolves (pending promises do not keep the event loop alive).
|
||||||
`common` module automatically adds a handler that makes the process crash - and
|
Node.js automatically crashes - and hence, the test fails - in the case of an
|
||||||
hence, the test fail - in the case of an `unhandledRejection` event. It is
|
`unhandledRejection` event.
|
||||||
possible to disable it with `common.disableCrashOnUnhandledRejection()` if
|
|
||||||
needed.
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
|
|
|
||||||
|
|
@ -61,14 +61,6 @@ On non-Windows platforms, this always returns `true`.
|
||||||
|
|
||||||
Creates a 10 MB file of all null characters.
|
Creates a 10 MB file of all null characters.
|
||||||
|
|
||||||
### `disableCrashOnUnhandledRejection()`
|
|
||||||
|
|
||||||
Removes the `process.on('unhandledRejection')` handler that crashes the process
|
|
||||||
after a tick. The handler is useful for tests that use Promises and need to make
|
|
||||||
sure no unexpected rejections occur, because currently they result in silent
|
|
||||||
failures. However, it is useful in some rare cases to disable it, for example if
|
|
||||||
the `unhandledRejection` hook is directly used by the test.
|
|
||||||
|
|
||||||
### `enoughTestCpu`
|
### `enoughTestCpu`
|
||||||
|
|
||||||
* [<boolean>][]
|
* [<boolean>][]
|
||||||
|
|
|
||||||
|
|
@ -628,10 +628,6 @@ function getBufferSources(buf) {
|
||||||
return [...getArrayBufferViews(buf), new Uint8Array(buf).buffer];
|
return [...getArrayBufferViews(buf), new Uint8Array(buf).buffer];
|
||||||
}
|
}
|
||||||
|
|
||||||
function disableCrashOnUnhandledRejection() {
|
|
||||||
process.on('unhandledRejection', () => {});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTTYfd() {
|
function getTTYfd() {
|
||||||
// Do our best to grab a tty fd.
|
// Do our best to grab a tty fd.
|
||||||
const tty = require('tty');
|
const tty = require('tty');
|
||||||
|
|
@ -732,7 +728,6 @@ const common = {
|
||||||
canCreateSymLink,
|
canCreateSymLink,
|
||||||
childShouldThrowAndAbort,
|
childShouldThrowAndAbort,
|
||||||
createZeroFilledFile,
|
createZeroFilledFile,
|
||||||
disableCrashOnUnhandledRejection,
|
|
||||||
expectsError,
|
expectsError,
|
||||||
expectWarning,
|
expectWarning,
|
||||||
gcUntil,
|
gcUntil,
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,6 @@ const {
|
||||||
skipIf32Bits,
|
skipIf32Bits,
|
||||||
getArrayBufferViews,
|
getArrayBufferViews,
|
||||||
getBufferSources,
|
getBufferSources,
|
||||||
disableCrashOnUnhandledRejection,
|
|
||||||
getTTYfd,
|
getTTYfd,
|
||||||
runWithInvalidFD
|
runWithInvalidFD
|
||||||
} = common;
|
} = common;
|
||||||
|
|
@ -92,7 +91,6 @@ export {
|
||||||
skipIf32Bits,
|
skipIf32Bits,
|
||||||
getArrayBufferViews,
|
getArrayBufferViews,
|
||||||
getBufferSources,
|
getBufferSources,
|
||||||
disableCrashOnUnhandledRejection,
|
|
||||||
getTTYfd,
|
getTTYfd,
|
||||||
runWithInvalidFD,
|
runWithInvalidFD,
|
||||||
createRequire
|
createRequire
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ function spawnChildProcess(inspectorFlags, scriptContents, scriptFile) {
|
||||||
const handler = tearDown.bind(null, child);
|
const handler = tearDown.bind(null, child);
|
||||||
process.on('exit', handler);
|
process.on('exit', handler);
|
||||||
process.on('uncaughtException', handler);
|
process.on('uncaughtException', handler);
|
||||||
common.disableCrashOnUnhandledRejection();
|
|
||||||
process.on('unhandledRejection', handler);
|
process.on('unhandledRejection', handler);
|
||||||
process.on('SIGINT', handler);
|
process.on('SIGINT', handler);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const common = require('../common');
|
require('../common');
|
||||||
|
|
||||||
if (process.argv[2] === 'async') {
|
if (process.argv[2] === 'async') {
|
||||||
common.disableCrashOnUnhandledRejection();
|
|
||||||
async function fn() {
|
async function fn() {
|
||||||
fn();
|
fn();
|
||||||
throw new Error();
|
throw new Error();
|
||||||
|
|
@ -16,7 +15,7 @@ const { spawnSync } = require('child_process');
|
||||||
|
|
||||||
const ret = spawnSync(
|
const ret = spawnSync(
|
||||||
process.execPath,
|
process.execPath,
|
||||||
['--stack_size=150', __filename, 'async'],
|
['--unhandled-rejections=none', '--stack_size=150', __filename, 'async'],
|
||||||
{ maxBuffer: Infinity }
|
{ maxBuffer: Infinity }
|
||||||
);
|
);
|
||||||
assert.strictEqual(ret.status, 0,
|
assert.strictEqual(ret.status, 0,
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,7 @@
|
||||||
|
|
||||||
import {
|
import {
|
||||||
mustCall,
|
mustCall,
|
||||||
disableCrashOnUnhandledRejection
|
|
||||||
} from '../common/index.mjs';
|
} from '../common/index.mjs';
|
||||||
|
|
||||||
disableCrashOnUnhandledRejection();
|
|
||||||
|
|
||||||
process.on('unhandledRejection', mustCall());
|
process.on('unhandledRejection', mustCall());
|
||||||
Promise.reject(new Error('should not be fatal error'));
|
Promise.reject(new Error('should not be fatal error'));
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
|
|
||||||
// This test verifies that DEP0018 does not occur when rejections are handled.
|
// This test verifies that DEP0018 does not occur when rejections are handled.
|
||||||
common.disableCrashOnUnhandledRejection();
|
|
||||||
process.on('warning', common.mustNotCall());
|
process.on('warning', common.mustNotCall());
|
||||||
process.on('unhandledRejection', common.mustCall());
|
process.on('unhandledRejection', common.mustCall());
|
||||||
Promise.reject(new Error());
|
Promise.reject(new Error());
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,6 @@ const common = require('../common');
|
||||||
const Countdown = require('../common/countdown');
|
const Countdown = require('../common/countdown');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
common.disableCrashOnUnhandledRejection();
|
|
||||||
|
|
||||||
// Verify that unhandled rejections always trigger uncaught exceptions instead
|
// Verify that unhandled rejections always trigger uncaught exceptions instead
|
||||||
// of triggering unhandled rejections.
|
// of triggering unhandled rejections.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,6 @@
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
common.disableCrashOnUnhandledRejection();
|
|
||||||
|
|
||||||
// Verify that ignoring unhandled rejection works fine and that no warning is
|
// Verify that ignoring unhandled rejection works fine and that no warning is
|
||||||
// logged even though there is no unhandledRejection hook attached.
|
// logged even though there is no unhandledRejection hook attached.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
|
|
||||||
common.disableCrashOnUnhandledRejection();
|
|
||||||
|
|
||||||
// Verify that ignoring unhandled rejection works fine and that no warning is
|
// Verify that ignoring unhandled rejection works fine and that no warning is
|
||||||
// logged.
|
// logged.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,6 @@ const common = require('../common');
|
||||||
const Countdown = require('../common/countdown');
|
const Countdown = require('../common/countdown');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
common.disableCrashOnUnhandledRejection();
|
|
||||||
|
|
||||||
// Verify that the unhandledRejection handler prevents triggering
|
// Verify that the unhandledRejection handler prevents triggering
|
||||||
// uncaught exceptions
|
// uncaught exceptions
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
|
|
||||||
common.disableCrashOnUnhandledRejection();
|
|
||||||
|
|
||||||
// Verify that ignoring unhandled rejection works fine and that no warning is
|
// Verify that ignoring unhandled rejection works fine and that no warning is
|
||||||
// logged.
|
// logged.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
|
// Flags: --unhandled-rejections=none
|
||||||
'use strict';
|
'use strict';
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
|
|
||||||
common.disableCrashOnUnhandledRejection();
|
|
||||||
|
|
||||||
function throwErr() {
|
function throwErr() {
|
||||||
throw new Error('Error from proxy');
|
throw new Error('Error from proxy');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
|
// Flags: --unhandled-rejections=none
|
||||||
'use strict';
|
'use strict';
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const { inspect } = require('util');
|
const { inspect } = require('util');
|
||||||
|
|
||||||
common.disableCrashOnUnhandledRejection();
|
|
||||||
|
|
||||||
const asyncTest = (function() {
|
const asyncTest = (function() {
|
||||||
let asyncTestsEnabled = false;
|
let asyncTestsEnabled = false;
|
||||||
let asyncTestLastCheck;
|
let asyncTestLastCheck;
|
||||||
|
|
@ -643,7 +642,6 @@ asyncTest('Throwing an error inside a rejectionHandled handler goes to' +
|
||||||
' unhandledException, and does not cause .catch() to throw an ' +
|
' unhandledException, and does not cause .catch() to throw an ' +
|
||||||
'exception', function(done) {
|
'exception', function(done) {
|
||||||
clean();
|
clean();
|
||||||
common.disableCrashOnUnhandledRejection();
|
|
||||||
const e = new Error();
|
const e = new Error();
|
||||||
const e2 = new Error();
|
const e2 = new Error();
|
||||||
const tearDownException = setupException(function(err) {
|
const tearDownException = setupException(function(err) {
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
|
|
||||||
common.disableCrashOnUnhandledRejection();
|
|
||||||
|
|
||||||
const expectedValueWarning = ['Symbol()'];
|
const expectedValueWarning = ['Symbol()'];
|
||||||
const expectedPromiseWarning = ['Unhandled promise rejection. ' +
|
const expectedPromiseWarning = ['Unhandled promise rejection. ' +
|
||||||
'This error originated either by throwing ' +
|
'This error originated either by throwing ' +
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@ const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const tmpdir = require('../common/tmpdir');
|
const tmpdir = require('../common/tmpdir');
|
||||||
|
|
||||||
common.disableCrashOnUnhandledRejection();
|
|
||||||
|
|
||||||
if (process.argv[2] === 'child') {
|
if (process.argv[2] === 'child') {
|
||||||
const p = Promise.reject(1); // Handled later
|
const p = Promise.reject(1); // Handled later
|
||||||
Promise.reject(2); // Unhandled
|
Promise.reject(2); // Unhandled
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user