Skip to content
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

test: remove common.disableCrashOnUnhandledRejection #38210

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions doc/guides/writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 0 additions & 8 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

* [<boolean>][]
Expand Down
5 changes: 0 additions & 5 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -732,7 +728,6 @@ const common = {
canCreateSymLink,
childShouldThrowAndAbort,
createZeroFilledFile,
disableCrashOnUnhandledRejection,
expectsError,
expectWarning,
gcUntil,
Expand Down
2 changes: 0 additions & 2 deletions test/common/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const {
skipIf32Bits,
getArrayBufferViews,
getBufferSources,
disableCrashOnUnhandledRejection,
getTTYfd,
runWithInvalidFD
} = common;
Expand Down Expand Up @@ -92,7 +91,6 @@ export {
skipIf32Bits,
getArrayBufferViews,
getBufferSources,
disableCrashOnUnhandledRejection,
getTTYfd,
runWithInvalidFD,
createRequire
Expand Down
1 change: 0 additions & 1 deletion test/common/inspector-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-async-wrap-pop-id-during-load.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions test/parallel/test-no-harmony-top-level-await.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
1 change: 0 additions & 1 deletion test/parallel/test-promise-handled-rejection-no-warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
2 changes: 0 additions & 2 deletions test/parallel/test-promise-unhandled-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 0 additions & 2 deletions test/parallel/test-promise-unhandled-silent-no-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 0 additions & 2 deletions test/parallel/test-promise-unhandled-silent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

const common = require('../common');

common.disableCrashOnUnhandledRejection();

// Verify that ignoring unhandled rejection works fine and that no warning is
// logged.

Expand Down
2 changes: 0 additions & 2 deletions test/parallel/test-promise-unhandled-throw-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions test/parallel/test-promise-unhandled-warn.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

const common = require('../common');

common.disableCrashOnUnhandledRejection();

// Verify that ignoring unhandled rejection works fine and that no warning is
// logged.

Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-promises-unhandled-proxy-rejections.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Flags: --unhandled-rejections=none
'use strict';
const common = require('../common');

common.disableCrashOnUnhandledRejection();

function throwErr() {
throw new Error('Error from proxy');
}
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-promises-unhandled-rejections.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions test/parallel/test-promises-unhandled-symbol-rejections.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand Down
2 changes: 0 additions & 2 deletions test/parallel/test-trace-events-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down