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 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');

View File

@ -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`
* [&lt;boolean>][] * [&lt;boolean>][]

View File

@ -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,

View File

@ -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

View File

@ -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);

View File

@ -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,

View File

@ -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'));

View File

@ -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());

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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

View File

@ -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.

View File

@ -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');
} }

View File

@ -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) {

View File

@ -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 ' +

View File

@ -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