8000 test(NODE-6804): convert unhandled rejections into uncaught exceptions · mongodb/node-mongodb-native@79328e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 79328e3

Browse files
committed
test(NODE-6804): convert unhandled rejections into uncaught exceptions
1 parent 398e361 commit 79328e3

File tree

11 files changed

+105
-78
lines changed

11 files changed

+105
-78
lines changed

.mocharc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
require: [
88
'source-map-support/register',
99
'ts-node/register',
10+
'test/tools/runner/throw_rejections.cjs',
1011
'test/tools/runner/chai_addons.ts',
1112
'test/tools/runner/ee_checker.ts'
1213
],
@@ -17,5 +18,5 @@ module.exports = {
1718
reporter: 'test/tools/reporter/mongodb_reporter.js',
1819
sort: true,
1920
color: true,
20-
'node-option': Number(major) >= 23 ? ['no-experimental-strip-types'] : undefined
21+
'node-option': Number(major) >= 23 ? ['no-experimental-strip-types'] : undefined
2122
};

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"@types/whatwg-url": "^11.0.5",
8282
"@typescript-eslint/eslint-plugin": "8.4.0",
8383
"@typescript-eslint/parser": "8.4.0",
84+
"aws4": "^1.13.2",
8485
"chai": "^4.4.1",
8586
"chai-subset": "^1.6.0",
8687
"chalk": "^4.1.2",

src/sdam/server.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
maxWireVersion,
4949
type MongoDBNamespace,
5050
noop,
51+
squashError,
5152
supportsRetryableWrites
5253
} from '../utils';
5354
import { throwIfWriteConcernError } from '../write_concern';
@@ -345,10 +346,8 @@ export class Server extends TypedEventEmitter<ServerEvents> {
345346
operationError instanceof MongoError &&
346347
operationError.code === MONGODB_ERROR_CODES.Reauthenticate
347348
) {
348-
reauthPromise = this.pool.reauthenticate(conn).catch(error => {
349-
reauthPromise = null;
350-
throw error;
351-
});
349+
// TODO: what do we do with this error? the signal has aborted so where should it be delivered?
350+
reauthPromise = this.pool.reauthenticate(conn).then(undefined, squashError);
352351

353352
await abortable(reauthPromise, options);
354353
reauthPromise = null; // only reachable if reauth succeeds

test/integration/node-specific/abort_signal.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,10 @@ describe('AbortSignal support', () => {
751751
...args
752752
) {
753753
if (args[1].find != null) {
754+
await sleep(1);
754755
commandStub.restore();
755756
controller.abort();
756-
throw new ReAuthenticationError({});
757+
throw new ReAuthenticationError({ message: 'This is a fake reauthentication error' });
757758
}
758759
return commandStub.wrappedMethod.apply(this, args);
759760
});
@@ -793,7 +794,7 @@ describe('AbortSignal support', () => {
793794
beforeEach(() => {
794795
sinon.stub(ConnectionPool.prototype, 'reauthenticate').callsFake(async function () {
795796
await sleep(1000);
796-
throw new Error();
797+
throw new Error('Rejecting reauthenticate for testing');
797798
});
798799
});
799800

test/manual/mocharc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ const [major] = process.versions.node.split('.');
44

55
/** @type {import("mocha").MochaOptions} */
66
module.exports = {
7-
require: ['ts-node/register', 'test/tools/runner/chai_addons.ts'],
7+
require: [
8+
'ts-node/register',
9+
'test/tools/runner/throw_rejections.cjs',
10+
'test/tools/runner/chai_addons.ts'
11+
],
812
reporter: 'test/tools/reporter/mongodb_reporter.js',
913
failZero: true,
1014
color: true,

test/mocha_lambda.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ const [major] = process.versions.node.split('.');
44

55
/** @type {import("mocha").MochaOptions} */
66
module.exports = {
7-
require: ['test/integration/node-specific/examples/setup.js'],
7+
require: [
8+
'test/tools/runner/throw_rejections.cjs',
9+
'test/integration/node-specific/examples/setup.js'
10+
],
811
extension: ['js'],
912
ui: 'test/tools/runner/metadata_ui.js',
1013
recursive: true,

test/mocha_mongodb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
require: [
88
'source-map-support/register',
99
'ts-node/register',
10+
'test/tools/runner/throw_rejections.cjs',
1011
'test/tools/runner/chai_addons.ts',
1112
'test/tools/runner/ee_checker.ts',
1213
'test/tools/runner/hooks/configuration.ts',
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// eslint-disable-next-line @typescript-eslint/no-require-imports
2+
const process = require('process');
3+
4+
process.on('unhandledRejection', error => {
5+
throw error;
6+
});

test/unit/assorted/optional_require.test.js

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0