Skip to content

Commit 2d1432c

Browse files
committed
test: clean up unified sdam implementation
1 parent 4add27a commit 2d1432c

File tree

5 files changed

+27
-25
lines changed

5 files changed

+27
-25
lines changed

test/tools/unified-spec-runner/entities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-non-null-assertion */
22
import { expect } from 'chai';
3-
import { EventEmitter } from 'stream';
3+
import { EventEmitter } from 'events';
44

55
import { ChangeStream } from '../../../src/change_stream';
66
import {
@@ -184,7 +184,7 @@ export class UnifiedMongoClient extends MongoClient {
184184
getCapturedEvents(
185185
eventType: 'command' | 'cmap' | 'sdam'
186186
): CommandEvent[] | CmapEvent[] | SdamEvent[];
187-
getCapturedEvents(eventType: 'all'): (CommandEvent | CmapEvent)[];
187+
getCapturedEvents(eventType: 'all'): (CommandEvent | CmapEvent | SdamEvent)[];
188188
getCapturedEvents(
189189
eventType: 'command' | 'cmap' | 'sdam' | 'all'
190190
): (CommandEvent | CmapEvent | SdamEvent)[] {

test/tools/unified-spec-runner/match.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ function compareEvents(
480480
for (const descriptionKey of expectedServerDescriptionKeys) {
481481
expect(actualEvent).to.have.property(descriptionKey);
482482
const expectedDescription =
483-
expectedEvent.serverDescriptionChangedEvent[descriptionKey] || {};
483+
expectedEvent.serverDescriptionChangedEvent[descriptionKey] ?? {};
484484
for (const nestedKey of Object.keys(expectedDescription)) {
485485
expect(actualEvent[descriptionKey]).to.have.property(
486486
nestedKey,

test/tools/unified-spec-runner/operations.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import { ReadPreference } from '../../../src/read_preference';
2121
import { WriteConcern } from '../../../src/write_concern';
2222
import { getSymbolFrom, sleep } from '../../tools/utils';
2323
import { TestConfiguration } from '../runner/config';
24-
import { CmapEvent, CommandEvent, EntitiesMap, UnifiedChangeStream } from './entities';
25-
import { expectErrorCheck, matchesEvents, resultCheck } from './match';
26-
import type { ExpectedEvent, ExpectedEventsForClient, OperationDescription } from './schema';
27-
import { translateOptions } from './unified-utils';
24+
import { EntitiesMap, UnifiedChangeStream } from './entities';
25+
import { expectErrorCheck, resultCheck } from './match';
26+
import type { ExpectedEvent, OperationDescription } from './schema';
27+
import { getMatchingEventCount, translateOptions } from './unified-utils';
2828

2929
interface OperationFunctionParams {
3030
client: MongoClient;
@@ -42,7 +42,7 @@ operations.set('createEntities', async ({ entities, operation, testConfig }) =>
4242
if (!operation.arguments?.entities) {
4343
throw new Error('encountered createEntities operation without entities argument');
4444
}
45-
await EntitiesMap.createEntities(testConfig, operation.arguments.entities, entities);
45+
await EntitiesMap.createEntities(testConfig, operation.arguments.entities!, entities);
4646
});
4747

4848
operations.set('abortTransaction', async ({ entities, operation }) => {
@@ -427,21 +427,6 @@ operations.set('wait', async ({ operation }) => {
427427
await sleep(operation.arguments!.ms);
428428
});
429429

430-
function getMatchingEventCount(event, client, entities): number {
431-
return client.getCapturedEvents('all').filter(capturedEvent => {
432-
try {
433-
matchesEvents(
434-
{ events: [event] } as ExpectedEventsForClient,
435-
[capturedEvent] as CommandEvent[] | CmapEvent[],
436-
entities
437-
);
438-
return true;
439-
} catch (e) {
440-
return false;
441-
}
442-
}).length;
443-
}
444-
445430
operations.set('waitForEvent', async ({ entities, operation }) => {
446431
expect(operation, 'Error in waitForEvent operation').to.have.property('arguments');
447432
const {

test/tools/unified-spec-runner/unified-utils.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import {
1414
} from '../../../src';
1515
import { getMongoDBClientEncryption } from '../../../src/utils';
1616
import { shouldRunServerlessTest } from '../../tools/utils';
17-
import { EntitiesMap } from './entities';
17+
import { CmapEvent, CommandEvent, EntitiesMap } from './entities';
18+
import { matchesEvents } from './match';
1819
import type {
1920
ClientEncryption,
2021
ClientEncryptionEntity,
2122
CollectionOrDatabaseOptions,
23+
ExpectedEventsForClient,
2224
KMSProvidersEntity,
2325
RunOnRequirement,
2426
StringOrPlaceholder
@@ -202,6 +204,21 @@ export function makeConnectionString(
202204
return connectionString.toString();
203205
}
204206

207+
export function getMatchingEventCount(event, client, entities): number {
208+
return client.getCapturedEvents('all').filter(capturedEvent => {
209+
try {
210+
matchesEvents(
211+
{ events: [event] } as ExpectedEventsForClient,
212+
[capturedEvent] as CommandEvent[] | CmapEvent[],
213+
entities
214+
);
215+
return true;
216+
} catch (e) {
217+
return false;
218+
}
219+
}).length;
220+
}
221+
205222
/**
206223
* attempts to import mongodb-client-encryption and extract the client encryption class for
207224
* use in the csfle unified tests

test/unit/assorted/server_discovery_and_monitoring.spec.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function collectTests(): Record<string, SDAMTest[]> {
5858
const testTypes = fs
5959
.readdirSync(specDir)
6060
.filter(d => fs.statSync(path.resolve(specDir, d)).isDirectory())
61-
.filter(d => d !== 'integration');
61+
.filter(d => d !== 'unified');
6262

6363
const tests = {};
6464
for (const testType of testTypes) {

0 commit comments

Comments
 (0)