Skip to content

Commit ba36dea

Browse files
committed
test(NODE-6692): check that event emitters have error listeners
1 parent 6b15f20 commit ba36dea

25 files changed

+129
-82
lines changed

.mocharc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"source-map-support/register",
55
"ts-node/register",
66
"test/tools/runner/chai_addons.ts",
7-
"test/tools/runner/hooks/unhandled_checker.ts"
7+
"test/tools/runner/ee_checker.ts"
88
],
99
"extension": [
1010
"js",

src/cmap/connection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
HostAddress,
4747
maxWireVersion,
4848
type MongoDBNamespace,
49+
noop,
4950
now,
5051
once,
5152
squashError,
@@ -229,6 +230,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
229230

230231
constructor(stream: Stream, options: ConnectionOptions) {
231232
super();
233+
this.on('error', noop);
232234

233235
this.socket = stream;
234236
this.id = options.id;

src/cmap/connection_pool.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
kDispose,
3535
List,
3636
makeCounter,
37+
noop,
3738
now,
3839
promiseWithResolvers
3940
} from '../utils';
@@ -200,6 +201,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
200201

201202
constructor(server: Server, options: ConnectionPoolOptions) {
202203
super();
204+
this.on('error', noop);
203205

204206
this.options = Object.freeze({
205207
connectionType: Connection,

src/cursor/abstract_cursor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
type Disposable,
2828
kDispose,
2929
type MongoDBNamespace,
30+
noop,
3031
squashError
3132
} from '../utils';
3233

@@ -267,6 +268,7 @@ export abstract class AbstractCursor<
267268
options: AbstractCursorOptions & Abortable = {}
268269
) {
269270
super();
271+
this.on('error', noop);
270272

271273
if (!client.s.isMongoClient) {
272274
throw new MongoRuntimeError('Cursor must be constructed with MongoClient');

src/gridfs/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { type Filter, TypedEventEmitter } from '../mongo_types';
77
import type { ReadPreference } from '../read_preference';
88
import type { Sort } from '../sort';
99
import { CSOTTimeoutContext } from '../timeout';
10-
import { resolveOptions } from '../utils';
10+
import { noop, resolveOptions } from '../utils';
1111
import { WriteConcern, type WriteConcernOptions } from '../write_concern';
1212
import type { FindOptions } from './../operations/find';
1313
import {
@@ -87,6 +87,7 @@ export class GridFSBucket extends TypedEventEmitter<GridFSBucketEvents> {
8787

8888
constructor(db: Db, options?: GridFSBucketOptions) {
8989
super();
90+
this.on('error', noop);
9091
this.setMaxListeners(0);
9192
const privateOptions = resolveOptions(db, {
9293
...DEFAULT_GRIDFS_BUCKET_OPTIONS,

src/mongo_client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
hostMatchesWildcards,
5959
isHostMatch,
6060
type MongoDBNamespace,
61+
noop,
6162
ns,
6263
resolveOptions,
6364
squashError
@@ -386,6 +387,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
386387

387388
constructor(url: string, options?: MongoClientOptions) {
388389
super();
390+
this.on('error', noop);
389391

390392
this.options = parseOptions(url, this, options);
391393

src/mongo_types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
type MongoLogger
2525
} from './mongo_logger';
2626
import type { Sort } from './sort';
27+
import { noop } from './utils';
2728

2829
/** @internal */
2930
export type TODO_NODE_3286 = any;
@@ -472,7 +473,12 @@ export class TypedEventEmitter<Events extends EventsDescription> extends EventEm
472473
}
473474

474475
/** @public */
475-
export class CancellationToken extends TypedEventEmitter<{ cancel(): void }> {}
476+
export class CancellationToken extends TypedEventEmitter<{ cancel(): void }> {
477+
constructor(...args: any[]) {
478+
super(...args);
479+
this.on('error', noop);
480+
}
481+
}
476482

477483
/** @public */
478484
export type Abortable = {

src/sdam/monitor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
type Callback,
1414
type EventEmitterWithState,
1515
makeStateMachine,
16+
noop,
1617
now,
1718
ns
1819
} from '../utils';
@@ -102,6 +103,7 @@ export class Monitor extends TypedEventEmitter<MonitorEvents> {
102103

103104
constructor(server: Server, options: MonitorOptions) {
104105
super();
106+
this.on('error', noop);
105107

106108
this.server = server;
107109
this.connection = null;

src/sdam/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
makeStateMachine,
4848
maxWireVersion,
4949
type MongoDBNamespace,
50+
noop,
5051
supportsRetryableWrites
5152
} from '../utils';
5253
import { throwIfWriteConcernError } from '../write_concern';
@@ -142,6 +143,7 @@ export class Server extends TypedEventEmitter<ServerEvents> {
142143
*/
143144
constructor(topology: Topology, description: ServerDescription, options: ServerOptions) {
144145
super();
146+
this.on('error', noop);
145147

146148
this.serverApi = options.serverApi;
147149

src/sdam/srv_polling.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { clearTimeout, setTimeout } from 'timers';
33

44
import { MongoRuntimeError } from '../error';
55
import { TypedEventEmitter } from '../mongo_types';
6-
import { checkParentDomainMatch, HostAddress, squashError } from '../utils';
6+
import { checkParentDomainMatch, HostAddress, noop, squashError } from '../utils';
77

88
/**
99
* @internal
@@ -49,6 +49,7 @@ export class SrvPoller extends TypedEventEmitter<SrvPollerEvents> {
4949

5050
constructor(options: SrvPollerOptions) {
5151
super();
52+
this.on('error', noop);
5253

5354
if (!options || !options.srvHost) {
5455
throw new MongoRuntimeError('Options for SrvPoller must exist and include srvHost');

0 commit comments

Comments
 (0)