From 11022ca4f21377f00827918ebbdf5ea3dbdb7d4a Mon Sep 17 00:00:00 2001 From: Isabel Atkinson Date: Wed, 13 Nov 2024 11:12:05 -0500 Subject: [PATCH] DRIVERS-943 Convert retryable writes command construction tests to unified format (#1697) Co-authored-by: Kevin Albertson --- source/retryable-writes/tests/README.md | 41 +---- .../tests/unified/aggregate-out-merge.json | 144 ++++++++++++++++ .../tests/unified/aggregate-out-merge.yml | 65 ++++++++ .../tests/unified/bulkWrite.json | 154 +++++++++++++++++- .../tests/unified/bulkWrite.yml | 64 ++++++++ .../client-bulkWrite-serverErrors.json | 15 +- .../unified/client-bulkWrite-serverErrors.yml | 3 + .../tests/unified/deleteMany.json | 22 ++- .../tests/unified/deleteMany.yml | 8 + .../tests/unified/deleteOne.json | 32 +++- .../tests/unified/deleteOne.yml | 12 ++ .../tests/unified/findOneAndDelete.json | 32 +++- .../tests/unified/findOneAndDelete.yml | 12 ++ .../tests/unified/findOneAndReplace.json | 32 +++- .../tests/unified/findOneAndReplace.yml | 12 ++ .../tests/unified/findOneAndUpdate.json | 32 +++- .../tests/unified/findOneAndUpdate.yml | 12 ++ .../tests/unified/insertMany.json | 59 ++++++- .../tests/unified/insertMany.yml | 23 +++ .../tests/unified/insertOne.json | 32 +++- .../tests/unified/insertOne.yml | 12 ++ .../tests/unified/replaceOne.json | 32 +++- .../tests/unified/replaceOne.yml | 12 ++ .../unified/unacknowledged-write-concern.json | 77 +++++++++ .../unified/unacknowledged-write-concern.yml | 40 +++++ .../tests/unified/updateMany.json | 22 ++- .../tests/unified/updateMany.yml | 8 + .../tests/unified/updateOne.json | 32 +++- .../tests/unified/updateOne.yml | 12 ++ 29 files changed, 1003 insertions(+), 50 deletions(-) create mode 100644 source/retryable-writes/tests/unified/aggregate-out-merge.json create mode 100644 source/retryable-writes/tests/unified/aggregate-out-merge.yml create mode 100644 source/retryable-writes/tests/unified/unacknowledged-write-concern.json create mode 100644 source/retryable-writes/tests/unified/unacknowledged-write-concern.yml diff --git a/source/retryable-writes/tests/README.md b/source/retryable-writes/tests/README.md index 8b6bed141a..d9c8890a20 100644 --- a/source/retryable-writes/tests/README.md +++ b/source/retryable-writes/tests/README.md @@ -63,42 +63,9 @@ insert command (because all documents in the first command will be processed in or delete that is split into two commands, the `skip` should be set to the number of statements in the first command to allow the fail point to trigger on the second command. -## Command Construction Tests - -Drivers should also assert that command documents are properly constructed with or without a transaction ID, depending -on whether the write operation is supported. -[Command Logging and Monitoring](../../command-logging-and-monitoring/command-logging-and-monitoring.md) may be used to -check for the presence of a `txnNumber` field in the command document. Note that command documents may always include an -`lsid` field per the [Driver Session](../../sessions/driver-sessions.md) specification. - -These tests may be run against both a replica set and shard cluster. - -Drivers should test that transaction IDs are never included in commands for unsupported write operations: - -- Write commands with unacknowledged write concerns (e.g. `{w: 0}`) -- Unsupported single-statement write operations - - `updateMany()` - - `deleteMany()` -- Unsupported multi-statement write operations - - `bulkWrite()` that includes `UpdateMany` or `DeleteMany` -- Unsupported write commands - - `aggregate` with write stage (e.g. `$out`, `$merge`) - -Drivers should test that transactions IDs are always included in commands for supported write operations: - -- Supported single-statement write operations - - `insertOne()` - - `updateOne()` - - `replaceOne()` - - `deleteOne()` - - `findOneAndDelete()` - - `findOneAndReplace()` - - `findOneAndUpdate()` -- Supported multi-statement write operations - - `insertMany()` with `ordered=true` - - `insertMany()` with `ordered=false` - - `bulkWrite()` with `ordered=true` (no `UpdateMany` or `DeleteMany`) - - `bulkWrite()` with `ordered=false` (no `UpdateMany` or `DeleteMany`) +## ~~Command Construction Tests~~ + +The command construction prose tests have been removed in favor of command event assertions in the unified format tests. ## Prose Tests @@ -297,6 +264,8 @@ debugger, code coverage tool, etc. ## Changelog +- 2024-10-29: Convert command construction tests to unified format. + - 2024-05-30: Migrated from reStructuredText to Markdown. - 2024-02-27: Convert legacy retryable writes tests to unified format. diff --git a/source/retryable-writes/tests/unified/aggregate-out-merge.json b/source/retryable-writes/tests/unified/aggregate-out-merge.json new file mode 100644 index 0000000000..c46bf8c31f --- /dev/null +++ b/source/retryable-writes/tests/unified/aggregate-out-merge.json @@ -0,0 +1,144 @@ +{ + "description": "aggregate with $out/$merge does not set txnNumber", + "schemaVersion": "1.3", + "runOnRequirements": [ + { + "minServerVersion": "3.6", + "topologies": [ + "replicaset", + "sharded", + "load-balanced" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "retryable-writes-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "mergeCollection", + "databaseName": "retryable-writes-tests", + "documents": [] + } + ], + "tests": [ + { + "description": "aggregate with $out does not set txnNumber", + "operations": [ + { + "object": "collection0", + "name": "aggregate", + "arguments": { + "pipeline": [ + { + "$sort": { + "x": 1 + } + }, + { + "$match": { + "_id": { + "$gt": 1 + } + } + }, + { + "$out": "outCollection" + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "aggregate", + "command": { + "txnNumber": { + "$$exists": false + } + } + } + } + ] + } + ] + }, + { + "description": "aggregate with $merge does not set txnNumber", + "runOnRequirements": [ + { + "minServerVersion": "4.1.11" + } + ], + "operations": [ + { + "object": "collection0", + "name": "aggregate", + "arguments": { + "pipeline": [ + { + "$sort": { + "x": 1 + } + }, + { + "$match": { + "_id": { + "$gt": 1 + } + } + }, + { + "$merge": { + "into": "mergeCollection" + } + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "aggregate", + "command": { + "txnNumber": { + "$$exists": false + } + } + } + } + ] + } + ] + } + ] +} diff --git a/source/retryable-writes/tests/unified/aggregate-out-merge.yml b/source/retryable-writes/tests/unified/aggregate-out-merge.yml new file mode 100644 index 0000000000..66e61a8ed0 --- /dev/null +++ b/source/retryable-writes/tests/unified/aggregate-out-merge.yml @@ -0,0 +1,65 @@ +description: "aggregate with $out/$merge does not set txnNumber" + +schemaVersion: "1.3" + +runOnRequirements: + - minServerVersion: "3.6" + topologies: + - replicaset + - sharded + - load-balanced + +createEntities: + - client: + id: &client0 client0 + observeEvents: [ commandStartedEvent ] + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name retryable-writes-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + +initialData: + # The output collection must already exist for $merge on a sharded cluster + - collectionName: &mergeCollection mergeCollection + databaseName: *database0Name + documents: [] + +tests: + - description: "aggregate with $out does not set txnNumber" + operations: + - object: *collection0 + name: aggregate + arguments: + pipeline: + - { $sort: { x: 1 } } + - { $match: { _id: { $gt: 1 } } } + - { $out: outCollection } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: aggregate + command: + txnNumber: { $$exists: false } + - description: "aggregate with $merge does not set txnNumber" + runOnRequirements: + - minServerVersion: "4.1.11" + operations: + - object: *collection0 + name: aggregate + arguments: + pipeline: + - { $sort: { x: 1 } } + - { $match: { _id: { $gt: 1 } } } + - { $merge: { into: *mergeCollection } } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: aggregate + command: + txnNumber: { $$exists: false } diff --git a/source/retryable-writes/tests/unified/bulkWrite.json b/source/retryable-writes/tests/unified/bulkWrite.json index 691321746b..f2bd9e0eb8 100644 --- a/source/retryable-writes/tests/unified/bulkWrite.json +++ b/source/retryable-writes/tests/unified/bulkWrite.json @@ -13,7 +13,10 @@ { "client": { "id": "client0", - "useMultipleMongoses": false + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent" + ] } }, { @@ -121,6 +124,53 @@ } ] } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "insert", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + }, + { + "commandStartedEvent": { + "commandName": "insert", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + }, + { + "commandStartedEvent": { + "commandName": "update", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + }, + { + "commandStartedEvent": { + "commandName": "delete", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + } + ] + } ] }, { @@ -510,6 +560,33 @@ } ] } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "insert", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + }, + { + "commandStartedEvent": { + "commandName": "insert", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + } + ] + } ] }, { @@ -926,6 +1003,81 @@ ] } ] + }, + { + "description": "collection bulkWrite with updateMany does not set txnNumber", + "operations": [ + { + "object": "collection0", + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "updateMany": { + "filter": {}, + "update": { + "$set": { + "x": 1 + } + } + } + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "update", + "command": { + "txnNumber": { + "$$exists": false + } + } + } + } + ] + } + ] + }, + { + "description": "collection bulkWrite with deleteMany does not set txnNumber", + "operations": [ + { + "object": "collection0", + "name": "bulkWrite", + "arguments": { + "requests": [ + { + "deleteMany": { + "filter": {} + } + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "delete", + "command": { + "txnNumber": { + "$$exists": false + } + } + } + } + ] + } + ] } ] } diff --git a/source/retryable-writes/tests/unified/bulkWrite.yml b/source/retryable-writes/tests/unified/bulkWrite.yml index d064c9dbc5..c92fd4b74a 100644 --- a/source/retryable-writes/tests/unified/bulkWrite.yml +++ b/source/retryable-writes/tests/unified/bulkWrite.yml @@ -12,6 +12,7 @@ createEntities: client: id: &client0 client0 useMultipleMongoses: false + observeEvents: [ commandStartedEvent ] - database: id: &database0 database0 @@ -72,6 +73,25 @@ tests: databaseName: *database_name documents: - { _id: 2, x: 23 } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: insert + command: + txnNumber: { $$exists: true } + - commandStartedEvent: + commandName: insert + command: + txnNumber: { $$exists: true } + - commandStartedEvent: + commandName: update + command: + txnNumber: { $$exists: true } + - commandStartedEvent: + commandName: delete + command: + txnNumber: { $$exists: true } - # Write operations in this ordered batch are intentionally sequenced so that # each write command consists of a single statement, which will fail on the @@ -266,6 +286,17 @@ tests: - { _id: 1, x: 11 } - { _id: 2, x: 22 } - { _id: 3, x: 33 } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: insert + command: + txnNumber: { $$exists: true } + - commandStartedEvent: + commandName: insert + command: + txnNumber: { $$exists: true } - description: 'First insertOne is never committed' operations: @@ -493,3 +524,36 @@ tests: documents: - { _id: 1, x: 12 } - { _id: 2, x: 22 } + - description: "collection bulkWrite with updateMany does not set txnNumber" + operations: + - object: *collection0 + name: bulkWrite + arguments: + requests: + - + updateMany: + filter: {} + update: { $set: { x: 1 } } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: update + command: + txnNumber: { $$exists: false } + - description: "collection bulkWrite with deleteMany does not set txnNumber" + operations: + - object: *collection0 + name: bulkWrite + arguments: + requests: + - + deleteMany: + filter: {} + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: delete + command: + txnNumber: { $$exists: false } \ No newline at end of file diff --git a/source/retryable-writes/tests/unified/client-bulkWrite-serverErrors.json b/source/retryable-writes/tests/unified/client-bulkWrite-serverErrors.json index f58c82bcc7..a1f7c8152a 100644 --- a/source/retryable-writes/tests/unified/client-bulkWrite-serverErrors.json +++ b/source/retryable-writes/tests/unified/client-bulkWrite-serverErrors.json @@ -428,7 +428,10 @@ { "ns": "retryable-writes-tests.coll0" } - ] + ], + "txnNumber": { + "$$exists": false + } } } } @@ -779,7 +782,10 @@ { "ns": "retryable-writes-tests.coll0" } - ] + ], + "txnNumber": { + "$$exists": false + } } } } @@ -861,7 +867,10 @@ { "ns": "retryable-writes-tests.coll0" } - ] + ], + "txnNumber": { + "$$exists": false + } } } } diff --git a/source/retryable-writes/tests/unified/client-bulkWrite-serverErrors.yml b/source/retryable-writes/tests/unified/client-bulkWrite-serverErrors.yml index 722e5cc8e0..9510682317 100644 --- a/source/retryable-writes/tests/unified/client-bulkWrite-serverErrors.yml +++ b/source/retryable-writes/tests/unified/client-bulkWrite-serverErrors.yml @@ -207,6 +207,7 @@ tests: multi: true nsInfo: - ns: *namespace + txnNumber: { $$exists: false } - description: "client bulkWrite with no multi: true operations succeeds after retryable writeConcernError" operations: - object: testRunner @@ -372,6 +373,7 @@ tests: multi: true nsInfo: - ns: *namespace + txnNumber: { $$exists: false } - description: "client bulkWrite with retryWrites: false does not retry" operations: - object: testRunner @@ -411,3 +413,4 @@ tests: document: { _id: 4, x: 44 } nsInfo: - ns: *namespace + txnNumber: { $$exists: false } diff --git a/source/retryable-writes/tests/unified/deleteMany.json b/source/retryable-writes/tests/unified/deleteMany.json index 087576cc0f..381f377954 100644 --- a/source/retryable-writes/tests/unified/deleteMany.json +++ b/source/retryable-writes/tests/unified/deleteMany.json @@ -15,7 +15,10 @@ { "client": { "id": "client0", - "useMultipleMongoses": true + "useMultipleMongoses": true, + "observeEvents": [ + "commandStartedEvent" + ] } }, { @@ -70,6 +73,23 @@ "databaseName": "retryable-writes-tests", "documents": [] } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "delete", + "command": { + "txnNumber": { + "$$exists": false + } + } + } + } + ] + } ] } ] diff --git a/source/retryable-writes/tests/unified/deleteMany.yml b/source/retryable-writes/tests/unified/deleteMany.yml index 31a6e07864..a05fe80769 100644 --- a/source/retryable-writes/tests/unified/deleteMany.yml +++ b/source/retryable-writes/tests/unified/deleteMany.yml @@ -12,6 +12,7 @@ createEntities: client: id: &client0 client0 useMultipleMongoses: true + observeEvents: [ commandStartedEvent ] - database: id: &database0 database0 @@ -47,3 +48,10 @@ tests: collectionName: *collection_name databaseName: *database_name documents: [] + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: delete + command: + txnNumber: { $$exists: false } diff --git a/source/retryable-writes/tests/unified/deleteOne.json b/source/retryable-writes/tests/unified/deleteOne.json index c3aaf88655..9e37ff8bcf 100644 --- a/source/retryable-writes/tests/unified/deleteOne.json +++ b/source/retryable-writes/tests/unified/deleteOne.json @@ -13,7 +13,10 @@ { "client": { "id": "client0", - "useMultipleMongoses": false + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent" + ] } }, { @@ -88,6 +91,33 @@ } ] } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "delete", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + }, + { + "commandStartedEvent": { + "commandName": "delete", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + } + ] + } ] }, { diff --git a/source/retryable-writes/tests/unified/deleteOne.yml b/source/retryable-writes/tests/unified/deleteOne.yml index ee31a33248..5a176f8293 100644 --- a/source/retryable-writes/tests/unified/deleteOne.yml +++ b/source/retryable-writes/tests/unified/deleteOne.yml @@ -12,6 +12,7 @@ createEntities: client: id: &client0 client0 useMultipleMongoses: false + observeEvents: [ commandStartedEvent ] - database: id: &database0 database0 @@ -56,6 +57,17 @@ tests: databaseName: *database_name documents: - { _id: 2, x: 22 } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: delete + command: + txnNumber: { $$exists: true } + - commandStartedEvent: + commandName: delete + command: + txnNumber: { $$exists: true } - description: 'DeleteOne is not committed on first attempt' operations: diff --git a/source/retryable-writes/tests/unified/findOneAndDelete.json b/source/retryable-writes/tests/unified/findOneAndDelete.json index 89dbb9d655..ebfb8ce665 100644 --- a/source/retryable-writes/tests/unified/findOneAndDelete.json +++ b/source/retryable-writes/tests/unified/findOneAndDelete.json @@ -13,7 +13,10 @@ { "client": { "id": "client0", - "useMultipleMongoses": false + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent" + ] } }, { @@ -94,6 +97,33 @@ } ] } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "findAndModify", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + }, + { + "commandStartedEvent": { + "commandName": "findAndModify", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + } + ] + } ] }, { diff --git a/source/retryable-writes/tests/unified/findOneAndDelete.yml b/source/retryable-writes/tests/unified/findOneAndDelete.yml index 464611a0f5..3788733216 100644 --- a/source/retryable-writes/tests/unified/findOneAndDelete.yml +++ b/source/retryable-writes/tests/unified/findOneAndDelete.yml @@ -12,6 +12,7 @@ createEntities: client: id: &client0 client0 useMultipleMongoses: false + observeEvents: [ commandStartedEvent ] - database: id: &database0 database0 @@ -56,6 +57,17 @@ tests: databaseName: *database_name documents: - { _id: 2, x: 22 } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: findAndModify + command: + txnNumber: { $$exists: true } + - commandStartedEvent: + commandName: findAndModify + command: + txnNumber: { $$exists: true } - description: 'FindOneAndDelete is not committed on first attempt' operations: diff --git a/source/retryable-writes/tests/unified/findOneAndReplace.json b/source/retryable-writes/tests/unified/findOneAndReplace.json index 6d1cc17974..638d15a41d 100644 --- a/source/retryable-writes/tests/unified/findOneAndReplace.json +++ b/source/retryable-writes/tests/unified/findOneAndReplace.json @@ -13,7 +13,10 @@ { "client": { "id": "client0", - "useMultipleMongoses": false + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent" + ] } }, { @@ -98,6 +101,33 @@ } ] } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "findAndModify", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + }, + { + "commandStartedEvent": { + "commandName": "findAndModify", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + } + ] + } ] }, { diff --git a/source/retryable-writes/tests/unified/findOneAndReplace.yml b/source/retryable-writes/tests/unified/findOneAndReplace.yml index 7a564143bd..cc2468264c 100644 --- a/source/retryable-writes/tests/unified/findOneAndReplace.yml +++ b/source/retryable-writes/tests/unified/findOneAndReplace.yml @@ -12,6 +12,7 @@ createEntities: client: id: &client0 client0 useMultipleMongoses: false + observeEvents: [ commandStartedEvent ] - database: id: &database0 database0 @@ -58,6 +59,17 @@ tests: documents: - { _id: 1, x: 111 } - { _id: 2, x: 22 } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: findAndModify + command: + txnNumber: { $$exists: true } + - commandStartedEvent: + commandName: findAndModify + command: + txnNumber: { $$exists: true } - description: 'FindOneAndReplace is not committed on first attempt' operations: diff --git a/source/retryable-writes/tests/unified/findOneAndUpdate.json b/source/retryable-writes/tests/unified/findOneAndUpdate.json index eb88fbe9b3..eefe98ae11 100644 --- a/source/retryable-writes/tests/unified/findOneAndUpdate.json +++ b/source/retryable-writes/tests/unified/findOneAndUpdate.json @@ -13,7 +13,10 @@ { "client": { "id": "client0", - "useMultipleMongoses": false + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent" + ] } }, { @@ -99,6 +102,33 @@ } ] } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "findAndModify", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + }, + { + "commandStartedEvent": { + "commandName": "findAndModify", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + } + ] + } ] }, { diff --git a/source/retryable-writes/tests/unified/findOneAndUpdate.yml b/source/retryable-writes/tests/unified/findOneAndUpdate.yml index 1a67f9b047..51c77f108c 100644 --- a/source/retryable-writes/tests/unified/findOneAndUpdate.yml +++ b/source/retryable-writes/tests/unified/findOneAndUpdate.yml @@ -12,6 +12,7 @@ createEntities: client: id: &client0 client0 useMultipleMongoses: false + observeEvents: [ commandStartedEvent ] - database: id: &database0 database0 @@ -58,6 +59,17 @@ tests: documents: - { _id: 1, x: 12 } - { _id: 2, x: 22 } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: findAndModify + command: + txnNumber: { $$exists: true } + - commandStartedEvent: + commandName: findAndModify + command: + txnNumber: { $$exists: true } - description: 'FindOneAndUpdate is not committed on first attempt' operations: diff --git a/source/retryable-writes/tests/unified/insertMany.json b/source/retryable-writes/tests/unified/insertMany.json index 47181d0a9e..35a18c46c6 100644 --- a/source/retryable-writes/tests/unified/insertMany.json +++ b/source/retryable-writes/tests/unified/insertMany.json @@ -13,7 +13,10 @@ { "client": { "id": "client0", - "useMultipleMongoses": false + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent" + ] } }, { @@ -107,6 +110,33 @@ } ] } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "insert", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + }, + { + "commandStartedEvent": { + "commandName": "insert", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + } + ] + } ] }, { @@ -172,6 +202,33 @@ } ] } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "insert", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + }, + { + "commandStartedEvent": { + "commandName": "insert", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + } + ] + } ] }, { diff --git a/source/retryable-writes/tests/unified/insertMany.yml b/source/retryable-writes/tests/unified/insertMany.yml index 0656b0c7ca..0ead50da7d 100644 --- a/source/retryable-writes/tests/unified/insertMany.yml +++ b/source/retryable-writes/tests/unified/insertMany.yml @@ -12,6 +12,7 @@ createEntities: client: id: &client0 client0 useMultipleMongoses: false + observeEvents: [ commandStartedEvent ] - database: id: &database0 database0 @@ -64,6 +65,17 @@ tests: - { _id: 1, x: 11 } - { _id: 2, x: 22 } - { _id: 3, x: 33 } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: insert + command: + txnNumber: { $$exists: true } + - commandStartedEvent: + commandName: insert + command: + txnNumber: { $$exists: true } - description: 'InsertMany with unordered execution' operations: @@ -97,6 +109,17 @@ tests: - { _id: 1, x: 11 } - { _id: 2, x: 22 } - { _id: 3, x: 33 } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: insert + command: + txnNumber: { $$exists: true } + - commandStartedEvent: + commandName: insert + command: + txnNumber: { $$exists: true } - description: 'InsertMany fails after multiple network errors' operations: diff --git a/source/retryable-writes/tests/unified/insertOne.json b/source/retryable-writes/tests/unified/insertOne.json index 61957415ed..a6afdbf224 100644 --- a/source/retryable-writes/tests/unified/insertOne.json +++ b/source/retryable-writes/tests/unified/insertOne.json @@ -13,7 +13,10 @@ { "client": { "id": "client0", - "useMultipleMongoses": false + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent" + ] } }, { @@ -101,6 +104,33 @@ } ] } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "insert", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + }, + { + "commandStartedEvent": { + "commandName": "insert", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + } + ] + } ] }, { diff --git a/source/retryable-writes/tests/unified/insertOne.yml b/source/retryable-writes/tests/unified/insertOne.yml index 50d7766b9c..9b45634823 100644 --- a/source/retryable-writes/tests/unified/insertOne.yml +++ b/source/retryable-writes/tests/unified/insertOne.yml @@ -12,6 +12,7 @@ createEntities: client: id: &client0 client0 useMultipleMongoses: false + observeEvents: [ commandStartedEvent ] - database: id: &database0 database0 @@ -58,6 +59,17 @@ tests: - { _id: 1, x: 11 } - { _id: 2, x: 22 } - { _id: 3, x: 33 } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: insert + command: + txnNumber: { $$exists: true } + - commandStartedEvent: + commandName: insert + command: + txnNumber: { $$exists: true } - description: 'InsertOne is not committed on first attempt' operations: diff --git a/source/retryable-writes/tests/unified/replaceOne.json b/source/retryable-writes/tests/unified/replaceOne.json index e58625bb5e..ee6e37d3bb 100644 --- a/source/retryable-writes/tests/unified/replaceOne.json +++ b/source/retryable-writes/tests/unified/replaceOne.json @@ -13,7 +13,10 @@ { "client": { "id": "client0", - "useMultipleMongoses": false + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent" + ] } }, { @@ -98,6 +101,33 @@ } ] } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "update", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + }, + { + "commandStartedEvent": { + "commandName": "update", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + } + ] + } ] }, { diff --git a/source/retryable-writes/tests/unified/replaceOne.yml b/source/retryable-writes/tests/unified/replaceOne.yml index 0cc92fb28f..90fc559037 100644 --- a/source/retryable-writes/tests/unified/replaceOne.yml +++ b/source/retryable-writes/tests/unified/replaceOne.yml @@ -12,6 +12,7 @@ createEntities: client: id: &client0 client0 useMultipleMongoses: false + observeEvents: [ commandStartedEvent ] - database: id: &database0 database0 @@ -60,6 +61,17 @@ tests: documents: - { _id: 1, x: 111 } - { _id: 2, x: 22 } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: update + command: + txnNumber: { $$exists: true } + - commandStartedEvent: + commandName: update + command: + txnNumber: { $$exists: true } - description: 'ReplaceOne is not committed on first attempt' operations: diff --git a/source/retryable-writes/tests/unified/unacknowledged-write-concern.json b/source/retryable-writes/tests/unified/unacknowledged-write-concern.json new file mode 100644 index 0000000000..eaa114acfd --- /dev/null +++ b/source/retryable-writes/tests/unified/unacknowledged-write-concern.json @@ -0,0 +1,77 @@ +{ + "description": "unacknowledged write does not set txnNumber", + "schemaVersion": "1.3", + "runOnRequirements": [ + { + "minServerVersion": "3.6", + "topologies": [ + "replicaset", + "sharded", + "load-balanced" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "retryable-writes-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0", + "collectionOptions": { + "writeConcern": { + "w": 0 + } + } + } + } + ], + "tests": [ + { + "description": "unacknowledged write does not set txnNumber", + "operations": [ + { + "object": "collection0", + "name": "insertOne", + "arguments": { + "document": { + "_id": 1, + "x": 11 + } + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "insert", + "command": { + "txnNumber": { + "$$exists": false + } + } + } + } + ] + } + ] + } + ] +} diff --git a/source/retryable-writes/tests/unified/unacknowledged-write-concern.yml b/source/retryable-writes/tests/unified/unacknowledged-write-concern.yml new file mode 100644 index 0000000000..3a0cce6ae8 --- /dev/null +++ b/source/retryable-writes/tests/unified/unacknowledged-write-concern.yml @@ -0,0 +1,40 @@ +description: "unacknowledged write does not set txnNumber" + +schemaVersion: "1.3" + +runOnRequirements: + - minServerVersion: "3.6" + topologies: + - replicaset + - sharded + - load-balanced + +createEntities: + - client: + id: &client0 client0 + observeEvents: [ commandStartedEvent ] + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name retryable-writes-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + collectionOptions: + writeConcern: { w: 0 } + +tests: + - description: "unacknowledged write does not set txnNumber" + operations: + - object: *collection0 + name: insertOne + arguments: + document: { _id: 1, x: 11 } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: insert + command: + txnNumber: { $$exists: false } diff --git a/source/retryable-writes/tests/unified/updateMany.json b/source/retryable-writes/tests/unified/updateMany.json index 260b7ad1c6..12c5204ee9 100644 --- a/source/retryable-writes/tests/unified/updateMany.json +++ b/source/retryable-writes/tests/unified/updateMany.json @@ -15,7 +15,10 @@ { "client": { "id": "client0", - "useMultipleMongoses": true + "useMultipleMongoses": true, + "observeEvents": [ + "commandStartedEvent" + ] } }, { @@ -86,6 +89,23 @@ } ] } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "update", + "command": { + "txnNumber": { + "$$exists": false + } + } + } + } + ] + } ] } ] diff --git a/source/retryable-writes/tests/unified/updateMany.yml b/source/retryable-writes/tests/unified/updateMany.yml index a1843b9d2a..d1febec309 100644 --- a/source/retryable-writes/tests/unified/updateMany.yml +++ b/source/retryable-writes/tests/unified/updateMany.yml @@ -12,6 +12,7 @@ createEntities: client: id: &client0 client0 useMultipleMongoses: true + observeEvents: [ commandStartedEvent ] - database: id: &database0 database0 @@ -52,3 +53,10 @@ tests: documents: - { _id: 1, x: 12 } - { _id: 2, x: 23 } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: update + command: + txnNumber: { $$exists: false } diff --git a/source/retryable-writes/tests/unified/updateOne.json b/source/retryable-writes/tests/unified/updateOne.json index 7947cef3c0..99ffba8e21 100644 --- a/source/retryable-writes/tests/unified/updateOne.json +++ b/source/retryable-writes/tests/unified/updateOne.json @@ -13,7 +13,10 @@ { "client": { "id": "client0", - "useMultipleMongoses": false + "useMultipleMongoses": false, + "observeEvents": [ + "commandStartedEvent" + ] } }, { @@ -99,6 +102,33 @@ } ] } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "commandName": "update", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + }, + { + "commandStartedEvent": { + "commandName": "update", + "command": { + "txnNumber": { + "$$exists": true + } + } + } + } + ] + } ] }, { diff --git a/source/retryable-writes/tests/unified/updateOne.yml b/source/retryable-writes/tests/unified/updateOne.yml index 55c42c1f4f..5c255b0da8 100644 --- a/source/retryable-writes/tests/unified/updateOne.yml +++ b/source/retryable-writes/tests/unified/updateOne.yml @@ -12,6 +12,7 @@ createEntities: client: id: &client0 client0 useMultipleMongoses: false + observeEvents: [ commandStartedEvent ] - database: id: &database0 database0 @@ -60,6 +61,17 @@ tests: documents: - { _id: 1, x: 12 } - { _id: 2, x: 22 } + expectEvents: + - client: client0 + events: + - commandStartedEvent: + commandName: update + command: + txnNumber: { $$exists: true } + - commandStartedEvent: + commandName: update + command: + txnNumber: { $$exists: true } - description: 'UpdateOne is not committed on first attempt' operations: