diff --git a/src/cmap/command_monitoring_events.ts b/src/cmap/command_monitoring_events.ts index 992b9dc47c9..b5e7c776d57 100644 --- a/src/cmap/command_monitoring_events.ts +++ b/src/cmap/command_monitoring_events.ts @@ -96,6 +96,7 @@ export class CommandSucceededEvent { commandName: string; reply: unknown; serviceId?: ObjectId; + databaseName: string; /** @internal */ name = COMMAND_SUCCEEDED; @@ -127,6 +128,7 @@ export class CommandSucceededEvent { this.duration = calculateDurationInMs(started); this.reply = maybeRedact(commandName, cmd, extractReply(reply)); this.serverConnectionId = serverConnectionId; + this.databaseName = command.databaseName; } /* @internal */ @@ -154,6 +156,7 @@ export class CommandFailedEvent { commandName: string; failure: Error; serviceId?: ObjectId; + databaseName: string; /** @internal */ name = COMMAND_FAILED; @@ -186,6 +189,7 @@ export class CommandFailedEvent { this.duration = calculateDurationInMs(started); this.failure = maybeRedact(commandName, cmd, error) as Error; this.serverConnectionId = serverConnectionId; + this.databaseName = command.databaseName; } /* @internal */ diff --git a/test/spec/unified-test-format/invalid/expectedCommandEvent-commandFailedEvent-databaseName-type.json b/test/spec/unified-test-format/invalid/expectedCommandEvent-commandFailedEvent-databaseName-type.json new file mode 100644 index 00000000000..f6a305b89a7 --- /dev/null +++ b/test/spec/unified-test-format/invalid/expectedCommandEvent-commandFailedEvent-databaseName-type.json @@ -0,0 +1,29 @@ +{ + "description": "expectedCommandEvent-commandFailedEvent-databaseName-type", + "schemaVersion": "1.15", + "createEntities": [ + { + "client": { + "id": "client0" + } + } + ], + "tests": [ + { + "description": "foo", + "operations": [], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandFailedEvent": { + "databaseName": 0 + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/unified-test-format/invalid/expectedCommandEvent-commandFailedEvent-databaseName-type.yml b/test/spec/unified-test-format/invalid/expectedCommandEvent-commandFailedEvent-databaseName-type.yml new file mode 100644 index 00000000000..9ab33ad59e2 --- /dev/null +++ b/test/spec/unified-test-format/invalid/expectedCommandEvent-commandFailedEvent-databaseName-type.yml @@ -0,0 +1,16 @@ +description: "expectedCommandEvent-commandFailedEvent-databaseName-type" + +schemaVersion: "1.15" + +createEntities: + - client: + id: &client0 "client0" + +tests: + - description: "foo" + operations: [] + expectEvents: + - client: *client0 + events: + - commandFailedEvent: + databaseName: 0 diff --git a/test/spec/unified-test-format/invalid/expectedCommandEvent-commandSucceededEvent-databaseName-type.json b/test/spec/unified-test-format/invalid/expectedCommandEvent-commandSucceededEvent-databaseName-type.json new file mode 100644 index 00000000000..47b8c8bb9d0 --- /dev/null +++ b/test/spec/unified-test-format/invalid/expectedCommandEvent-commandSucceededEvent-databaseName-type.json @@ -0,0 +1,29 @@ +{ + "description": "expectedCommandEvent-commandSucceededEvent-databaseName-type", + "schemaVersion": "1.15", + "createEntities": [ + { + "client": { + "id": "client0" + } + } + ], + "tests": [ + { + "description": "foo", + "operations": [], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandSucceededEvent": { + "databaseName": 0 + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/unified-test-format/invalid/expectedCommandEvent-commandSucceededEvent-databaseName-type.yml b/test/spec/unified-test-format/invalid/expectedCommandEvent-commandSucceededEvent-databaseName-type.yml new file mode 100644 index 00000000000..94adc2b7305 --- /dev/null +++ b/test/spec/unified-test-format/invalid/expectedCommandEvent-commandSucceededEvent-databaseName-type.yml @@ -0,0 +1,16 @@ +description: "expectedCommandEvent-commandSucceededEvent-databaseName-type" + +schemaVersion: "1.15" + +createEntities: + - client: + id: &client0 "client0" + +tests: + - description: "foo" + operations: [] + expectEvents: + - client: *client0 + events: + - commandSucceededEvent: + databaseName: 0 diff --git a/test/tools/unified-spec-runner/match.ts b/test/tools/unified-spec-runner/match.ts index 1b8d0d7836e..06a23388c01 100644 --- a/test/tools/unified-spec-runner/match.ts +++ b/test/tools/unified-spec-runner/match.ts @@ -478,37 +478,53 @@ function compareCommandStartedEvents( function compareCommandSucceededEvents( actual: CommandSucceededEvent, - expected: ExpectedCommandEvent['commandSucceededEvent'], + expected: NonNullable, entities: EntitiesMap, prefix: string ) { - if (expected!.reply) { - resultCheck(actual.reply as Document, expected!.reply, entities, [prefix]); + if (expected.reply) { + resultCheck(actual.reply as Document, expected.reply, entities, [prefix]); } - if (expected!.commandName) { + if (expected.commandName) { expect( - expected!.commandName, - `expected ${prefix}.commandName to equal ${expected!.commandName} but received ${ + expected.commandName, + `expected ${prefix}.commandName to equal ${expected.commandName} but received ${ actual.commandName }` ).to.equal(actual.commandName); } + if (expected.databaseName) { + expect( + expected.databaseName, + `expected ${prefix}.databaseName to equal ${expected.databaseName} but received ${ + actual.databaseName + }` + ).to.equal(actual.databaseName); + } } function compareCommandFailedEvents( actual: CommandFailedEvent, - expected: ExpectedCommandEvent['commandFailedEvent'], - entities: EntitiesMap, + expected: NonNullable, + _entities: EntitiesMap, prefix: string ) { - if (expected!.commandName) { + if (expected.commandName) { expect( - expected!.commandName, - `expected ${prefix}.commandName to equal ${expected!.commandName} but received ${ + expected.commandName, + `expected ${prefix}.commandName to equal ${expected.commandName} but received ${ actual.commandName }` ).to.equal(actual.commandName); } + if (expected.databaseName) { + expect( + expected.databaseName, + `expected ${prefix}.databaseName to equal ${expected.databaseName} but received ${ + actual.databaseName + }` + ).to.equal(actual.databaseName); + } } function expectInstanceOf any>( diff --git a/test/tools/unified-spec-runner/schema.ts b/test/tools/unified-spec-runner/schema.ts index d52192e645c..cd2bd3ff3d5 100644 --- a/test/tools/unified-spec-runner/schema.ts +++ b/test/tools/unified-spec-runner/schema.ts @@ -312,10 +312,12 @@ export interface ExpectedCommandEvent { commandSucceededEvent?: { reply?: Document; commandName?: string; + databaseName?: string; hasServerConnectionId?: boolean; }; commandFailedEvent?: { commandName?: string; + databaseName?: string; hasServerConnectionId?: boolean; }; }