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:
Michaël Zasso 2021-04-12 16:04:44 +02:00
parent 3377eb9641
commit 05df701e70
No known key found for this signature in database
GPG Key ID: 770F7A9A5AE15600
17 changed files with 7 additions and 47 deletions

View File

@ -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
`onFulfilled` handler, otherwise the test could successfully finish if the
promise never resolves (pending promises do not keep the event loop alive). The
`common` module automatically adds a handler that makes the process crash - and
hence, the test fail - in the case of an `unhandledRejection` event. It is
possible to disable it with `common.disableCrashOnUnhandledRejection()` if
needed.
promise never resolves (pending promises do not keep the event loop alive).
Node.js automatically crashes - and hence, the test fails - in the case of an
`unhandledRejection` event.
```js
const common = require('../common');

View File

@ -61,14 +61,6 @@ On non-Windows platforms, this always returns `true`.
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`
* [&lt;boolean>][]

View File

@ -628,10 +628,6 @@ function getBufferSources(buf) {
return [...getArrayBufferViews(buf), new Uint8Array(buf).buffer];
}
function disableCrashOnUnhandledRejection() {
process.on('unhandledRejection', () => {});
}
function getTTYfd() {
// Do our best to grab a tty fd.
const tty = require('tty');
@ -732,7 +728,6 @@ const common = {
canCreateSymLink,
childShouldThrowAndAbort,
createZeroFilledFile,
disableCrashOnUnhandledRejection,
expectsError,
expectWarning,
gcUntil,

View File

@ -46,7 +46,6 @@ const {
skipIf32Bits,
getArrayBufferViews,
getBufferSources,
disableCrashOnUnhandledRejection,
getTTYfd,
runWithInvalidFD
} = common;
@ -92,7 +91,6 @@ export {
skipIf32Bits,
getArrayBufferViews,
getBufferSources,
disableCrashOnUnhandledRejection,
getTTYfd,
runWithInvalidFD,
createRequire

View File

@ -25,7 +25,6 @@ function spawnChildProcess(inspectorFlags, scriptContents, scriptFile) {
const handler = tearDown.bind(null, child);
process.on('exit', handler);
process.on('uncaughtException', handler);
common.disableCrashOnUnhandledRejection();
process.on('unhandledRejection', handler);
process.on('SIGINT', handler);

View File

@ -1,9 +1,8 @@
'use strict';
const common = require('../common');
require('../common');
if (process.argv[2] === 'async') {
common.disableCrashOnUnhandledRejection();
async function fn() {
fn();
throw new Error();
@ -16,7 +15,7 @@ const { spawnSync } = require('child_process');
const ret = spawnSync(
process.execPath,
['--stack_size=150', __filename, 'async'],
['--unhandled-rejections=none', '--stack_size=150', __filename, 'async'],
{ maxBuffer: Infinity }
);
assert.strictEqual(ret.status, 0,

View File

@ -2,10 +2,7 @@
import {
mustCall,
disableCrashOnUnhandledRejection
} from '../common/index.mjs';
disableCrashOnUnhandledRejection();
process.on('unhandledRejection', mustCall());
Promise.reject(new Error('should not be fatal error'));

View File

@ -2,7 +2,6 @@
const common = require('../common');
// This test verifies that DEP0018 does not occur when rejections are handled.
common.disableCrashOnUnhandledRejection();
process.on('warning', common.mustNotCall());
process.on('unhandledRejection', common.mustCall());
Promise.reject(new Error());

View File

@ -5,8 +5,6 @@ const common = require('../common');
const Countdown = require('../common/countdown');
const assert = require('assert');
common.disableCrashOnUnhandledRejection();
// Verify that unhandled rejections always trigger uncaught exceptions instead
// of triggering unhandled rejections.

View File

@ -4,8 +4,6 @@
const common = require('../common');
const assert = require('assert');
common.disableCrashOnUnhandledRejection();
// Verify that ignoring unhandled rejection works fine and that no warning is
// logged even though there is no unhandledRejection hook attached.

View File

@ -3,8 +3,6 @@
const common = require('../common');
common.disableCrashOnUnhandledRejection();
// Verify that ignoring unhandled rejection works fine and that no warning is
// logged.

View File

@ -5,8 +5,6 @@ const common = require('../common');
const Countdown = require('../common/countdown');
const assert = require('assert');
common.disableCrashOnUnhandledRejection();
// Verify that the unhandledRejection handler prevents triggering
// uncaught exceptions

View File

@ -3,8 +3,6 @@
const common = require('../common');
common.disableCrashOnUnhandledRejection();
// Verify that ignoring unhandled rejection works fine and that no warning is
// logged.

View File

@ -1,8 +1,7 @@
// Flags: --unhandled-rejections=none
'use strict';
const common = require('../common');
common.disableCrashOnUnhandledRejection();
function throwErr() {
throw new Error('Error from proxy');
}

View File

@ -1,10 +1,9 @@
// Flags: --unhandled-rejections=none
'use strict';
const common = require('../common');
const assert = require('assert');
const { inspect } = require('util');
common.disableCrashOnUnhandledRejection();
const asyncTest = (function() {
let asyncTestsEnabled = false;
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 ' +
'exception', function(done) {
clean();
common.disableCrashOnUnhandledRejection();
const e = new Error();
const e2 = new Error();
const tearDownException = setupException(function(err) {

View File

@ -2,8 +2,6 @@
'use strict';
const common = require('../common');
common.disableCrashOnUnhandledRejection();
const expectedValueWarning = ['Symbol()'];
const expectedPromiseWarning = ['Unhandled promise rejection. ' +
'This error originated either by throwing ' +

View File

@ -6,8 +6,6 @@ const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir');
common.disableCrashOnUnhandledRejection();
if (process.argv[2] === 'child') {
const p = Promise.reject(1); // Handled later
Promise.reject(2); // Unhandled