Skip to content

Commit 138b841

Browse files
committed
refactor: update constants
1 parent bc4fd0e commit 138b841

File tree

4 files changed

+26
-49
lines changed

4 files changed

+26
-49
lines changed

src/cmap/errors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MongoDriverError } from '../error';
1+
import { MongoDriverError, MongoNetworkError } from '../error';
22
import type { ConnectionPool } from './connection_pool';
33

44
/**
@@ -23,7 +23,7 @@ export class PoolClosedError extends MongoDriverError {
2323
* An error indicating a connection pool is currently paused
2424
* @category Error
2525
*/
26-
export class PoolClearedError extends MongoDriverError {
26+
export class PoolClearedError extends MongoNetworkError {
2727
// TODO: needs to extend RetryableError or be marked retryable in some other way per spec
2828
/** The address of the connection pool */
2929
address: string;

src/constants.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,16 @@ export const HEARTBEAT_EVENTS = Object.freeze([
5858
/** @public */
5959
export const CMAP_EVENTS = Object.freeze([
6060
CONNECTION_POOL_CREATED,
61+
CONNECTION_POOL_READY,
62+
CONNECTION_POOL_CLEARED,
6163
CONNECTION_POOL_CLOSED,
6264
CONNECTION_CREATED,
6365
CONNECTION_READY,
6466
CONNECTION_CLOSED,
6567
CONNECTION_CHECK_OUT_STARTED,
6668
CONNECTION_CHECK_OUT_FAILED,
6769
CONNECTION_CHECKED_OUT,
68-
CONNECTION_CHECKED_IN,
69-
CONNECTION_POOL_CLEARED
70+
CONNECTION_CHECKED_IN
7071
] as const);
7172

7273
/** @public */

test/tools/cmap_spec_runner.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { promisify } from 'util';
55

66
import { Connection, HostAddress, MongoClient } from '../../src';
77
import { ConnectionPool, ConnectionPoolOptions } from '../../src/cmap/connection_pool';
8+
import { CMAP_EVENTS } from '../../src/constants';
89
import { makeClientMetadata, shuffle } from '../../src/utils';
910
import { isAnyRequirementSatisfied } from './unified-spec-runner/unified-utils';
1011
import { FailPoint, sleep } from './utils';
@@ -80,19 +81,7 @@ export type CmapTest = {
8081
failPoint?: FailPoint;
8182
};
8283

83-
const ALL_POOL_EVENTS = new Set([
84-
ConnectionPool.CONNECTION_POOL_CREATED,
85-
ConnectionPool.CONNECTION_POOL_CLOSED,
86-
ConnectionPool.CONNECTION_POOL_CLEARED,
87-
ConnectionPool.CONNECTION_POOL_READY,
88-
ConnectionPool.CONNECTION_CREATED,
89-
ConnectionPool.CONNECTION_READY,
90-
ConnectionPool.CONNECTION_CLOSED,
91-
ConnectionPool.CONNECTION_CHECK_OUT_STARTED,
92-
ConnectionPool.CONNECTION_CHECK_OUT_FAILED,
93-
ConnectionPool.CONNECTION_CHECKED_OUT,
94-
ConnectionPool.CONNECTION_CHECKED_IN
95-
]);
84+
const ALL_POOL_EVENTS = new Set(CMAP_EVENTS);
9685

9786
function getEventType(event) {
9887
const eventName = event.constructor.name;

test/tools/spec-runner/index.js

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ const { EJSON } = require('bson');
88
const { isRecord } = require('../../../src/utils');
99
const TestRunnerContext = require('./context').TestRunnerContext;
1010
const resolveConnectionString = require('./utils').resolveConnectionString;
11-
const { LEGACY_HELLO_COMMAND } = require('../../../src/constants');
11+
const {
12+
LEGACY_HELLO_COMMAND,
13+
CMAP_EVENTS: SOURCE_CMAP_EVENTS,
14+
TOPOLOGY_EVENTS,
15+
HEARTBEAT_EVENTS
16+
} = require('../../../src/constants');
1217
const { isAnyRequirementSatisfied } = require('../unified-spec-runner/unified-utils');
1318
const ClientSideEncryptionFilter = require('../runner/filters/client_encryption_filter');
1419

@@ -158,16 +163,16 @@ function generateTopologyTests(testSuites, testContext, filter) {
158163

159164
const { spec } = this.currentTest;
160165

161-
if (
162-
shouldRun &&
163-
spec.operations.some(
164-
op => op.name === 'waitForEvent' && op.arguments.event === 'PoolReadyEvent'
165-
)
166-
) {
167-
this.currentTest.skipReason =
168-
'TODO(NODE-2994): Connection storms work will add new events to connection pool';
169-
shouldRun = false;
170-
}
166+
// if (
167+
// shouldRun &&
168+
// spec.operations.some(
169+
// op => op.name === 'waitForEvent' && op.arguments.event === 'PoolReadyEvent'
170+
// )
171+
// ) {
172+
// this.currentTest.skipReason =
173+
// 'TODO(NODE-2994): Connection storms work will add new events to connection pool';
174+
// shouldRun = false;
175+
// }
171176

172177
if (shouldRun && spec.skipReason) {
173178
this.currentTest.skipReason = spec.skipReason;
@@ -329,29 +334,11 @@ function parseSessionOptions(options) {
329334

330335
const IGNORED_COMMANDS = new Set([LEGACY_HELLO_COMMAND, 'configureFailPoint', 'endSessions']);
331336
const SDAM_EVENTS = new Set([
332-
'serverOpening',
333-
'serverClosed',
334-
'serverDescriptionChanged',
335-
'topologyOpening',
336-
'topologyClosed',
337-
'topologyDescriptionChanged',
338-
'serverHeartbeatStarted',
339-
'serverHeartbeatSucceeded',
340-
'serverHeartbeatFailed'
337+
...TOPOLOGY_EVENTS.filter(ev => !['error', 'timeout', 'close'].includes(ev)),
338+
...HEARTBEAT_EVENTS
341339
]);
342340

343-
const CMAP_EVENTS = new Set([
344-
'connectionPoolCreated',
345-
'connectionPoolClosed',
346-
'connectionCreated',
347-
'connectionReady',
348-
'connectionClosed',
349-
'connectionCheckOutStarted',
350-
'connectionCheckOutFailed',
351-
'connectionCheckedOut',
352-
'connectionCheckedIn',
353-
'connectionPoolCleared'
354-
]);
341+
const CMAP_EVENTS = new Set(SOURCE_CMAP_EVENTS);
355342

356343
function runTestSuiteTest(configuration, spec, context) {
357344
context.commandEvents = [];

0 commit comments

Comments
 (0)