Skip to content

Commit e5e6b2a

Browse files
add dbName to cmd events
1 parent 2e06e53 commit e5e6b2a

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

src/cmap/command_monitoring_events.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export class CommandSucceededEvent {
9696
commandName: string;
9797
reply: unknown;
9898
serviceId?: ObjectId;
99+
databaseName: string;
99100
/** @internal */
100101
name = COMMAND_SUCCEEDED;
101102

@@ -127,6 +128,7 @@ export class CommandSucceededEvent {
127128
this.duration = calculateDurationInMs(started);
128129
this.reply = maybeRedact(commandName, cmd, extractReply(reply));
129130
this.serverConnectionId = serverConnectionId;
131+
this.databaseName = command.databaseName;
130132
}
131133

132134
/* @internal */
@@ -154,6 +156,7 @@ export class CommandFailedEvent {
154156
commandName: string;
155157
failure: Error;
156158
serviceId?: ObjectId;
159+
databaseName: string;
157160
/** @internal */
158161
name = COMMAND_FAILED;
159162

@@ -186,6 +189,7 @@ export class CommandFailedEvent {
186189
this.duration = calculateDurationInMs(started);
187190
this.failure = maybeRedact(commandName, cmd, error) as Error;
188191
this.serverConnectionId = serverConnectionId;
192+
this.databaseName = command.databaseName;
189193
}
190194

191195
/* @internal */

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

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -461,54 +461,64 @@ function compareCommandStartedEvents(
461461
if (expected!.commandName) {
462462
expect(
463463
expected!.commandName,
464-
`expected ${prefix}.commandName to equal ${expected!.commandName} but received ${
465-
actual.commandName
464+
`expected ${prefix}.commandName to equal ${expected!.commandName} but received ${actual.commandName
466465
}`
467466
).to.equal(actual.commandName);
468467
}
469468
if (expected!.databaseName) {
470469
expect(
471470
expected!.databaseName,
472-
`expected ${prefix}.databaseName to equal ${expected!.databaseName} but received ${
473-
actual.databaseName
471+
`expected ${prefix}.databaseName to equal ${expected!.databaseName} but received ${actual.databaseName
474472
}`
475473
).to.equal(actual.databaseName);
476474
}
477475
}
478476

479477
function compareCommandSucceededEvents(
480478
actual: CommandSucceededEvent,
481-
expected: ExpectedCommandEvent['commandSucceededEvent'],
479+
expected: NonNullable<ExpectedCommandEvent['commandSucceededEvent']>,
482480
entities: EntitiesMap,
483481
prefix: string
484482
) {
485-
if (expected!.reply) {
486-
resultCheck(actual.reply as Document, expected!.reply, entities, [prefix]);
483+
if (expected.reply) {
484+
resultCheck(actual.reply as Document, expected.reply, entities, [prefix]);
487485
}
488-
if (expected!.commandName) {
486+
if (expected.commandName) {
489487
expect(
490-
expected!.commandName,
491-
`expected ${prefix}.commandName to equal ${expected!.commandName} but received ${
492-
actual.commandName
488+
expected.commandName,
489+
`expected ${prefix}.commandName to equal ${expected.commandName} but received ${actual.commandName
493490
}`
494491
).to.equal(actual.commandName);
495492
}
493+
if (expected.databaseName) {
494+
expect(
495+
expected.databaseName,
496+
`expected ${prefix}.databaseName to equal ${expected.databaseName} but received ${actual.databaseName
497+
}`
498+
).to.equal(actual.databaseName);
499+
}
496500
}
497501

498502
function compareCommandFailedEvents(
499503
actual: CommandFailedEvent,
500-
expected: ExpectedCommandEvent['commandFailedEvent'],
501-
entities: EntitiesMap,
504+
expected: NonNullable<ExpectedCommandEvent['commandFailedEvent']>,
505+
_entities: EntitiesMap,
502506
prefix: string
503507
) {
504-
if (expected!.commandName) {
508+
if (expected.commandName) {
505509
expect(
506-
expected!.commandName,
507-
`expected ${prefix}.commandName to equal ${expected!.commandName} but received ${
508-
actual.commandName
510+
expected.commandName,
511+
`expected ${prefix}.commandName to equal ${expected.commandName} but received ${actual.commandName
509512
}`
510513
).to.equal(actual.commandName);
511514
}
515+
if (expected.databaseName) {
516+
expect(
517+
expected.databaseName,
518+
`expected ${prefix}.databaseName to equal ${expected.databaseName} but received ${actual.databaseName
519+
}`
520+
).to.equal(actual.databaseName);
521+
}
512522
}
513523

514524
function expectInstanceOf<T extends new (...args: any[]) => any>(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,12 @@ export interface ExpectedCommandEvent {
312312
commandSucceededEvent?: {
313313
reply?: Document;
314314
commandName?: string;
315+
databaseName?: string;
315316
hasServerConnectionId?: boolean;
316317
};
317318
commandFailedEvent?: {
318319
commandName?: string;
320+
databaseName?: string;
319321
hasServerConnectionId?: boolean;
320322
};
321323
}

0 commit comments

Comments
 (0)