From 60d5d8acb0498d0c7bb53c5866e561a302e32f11 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Mon, 11 Mar 2024 22:33:41 -0400 Subject: [PATCH 1/2] Remove legacy default write concern tests --- tests/SpecTests/ReadWriteConcernSpecTest.php | 113 ---- .../operation/default-write-concern-2.6.json | 544 ------------------ .../operation/default-write-concern-3.2.json | 125 ---- .../operation/default-write-concern-3.4.json | 216 ------- .../operation/default-write-concern-4.2.json | 87 --- 5 files changed, 1085 deletions(-) delete mode 100644 tests/SpecTests/ReadWriteConcernSpecTest.php delete mode 100644 tests/SpecTests/read-write-concern/operation/default-write-concern-2.6.json delete mode 100644 tests/SpecTests/read-write-concern/operation/default-write-concern-3.2.json delete mode 100644 tests/SpecTests/read-write-concern/operation/default-write-concern-3.4.json delete mode 100644 tests/SpecTests/read-write-concern/operation/default-write-concern-4.2.json diff --git a/tests/SpecTests/ReadWriteConcernSpecTest.php b/tests/SpecTests/ReadWriteConcernSpecTest.php deleted file mode 100644 index cefbd6720..000000000 --- a/tests/SpecTests/ReadWriteConcernSpecTest.php +++ /dev/null @@ -1,113 +0,0 @@ - $value) { - if ($value === null) { - static::assertObjectNotHasAttribute($key, $actual); - unset($expected->{$key}); - } - } - - static::assertDocumentsMatch($expected, $actual); - } - - /** - * Execute an individual test case from the specification. - * - * @dataProvider provideTests - * @param stdClass $test Individual "tests[]" document - * @param array $runOn Top-level "runOn" array with server requirements - * @param array $data Top-level "data" array to initialize collection - * @param string $databaseName Name of database under test - * @param string $collectionName Name of collection under test - */ - public function testReadWriteConcern(stdClass $test, ?array $runOn, array $data, ?string $databaseName = null, ?string $collectionName = null): void - { - if (isset(self::$incompleteTests[$this->dataDescription()])) { - $this->markTestIncomplete(self::$incompleteTests[$this->dataDescription()]); - } - - if (isset($runOn)) { - $this->checkServerRequirements($runOn); - } - - if (isset($test->skipReason)) { - $this->markTestSkipped($test->skipReason); - } - - $databaseName ??= $this->getDatabaseName(); - $collectionName ??= $this->getCollectionName(); - - $context = Context::fromReadWriteConcern($test, $databaseName, $collectionName); - $this->setContext($context); - - $this->dropTestAndOutcomeCollections(); - $this->insertDataFixtures($data); - - if (isset($test->failPoint)) { - $this->configureFailPoint($test->failPoint); - } - - if (isset($test->expectations)) { - $commandExpectations = CommandExpectations::fromReadWriteConcern($context->getClient(), $test->expectations); - $commandExpectations->startMonitoring(); - } - - foreach ($test->operations as $operation) { - Operation::fromReadWriteConcern($operation)->assert($this, $context); - } - - if (isset($commandExpectations)) { - $commandExpectations->stopMonitoring(); - $commandExpectations->assert($this, $context); - } - - if (isset($test->outcome->collection->data)) { - $this->assertOutcomeCollectionData($test->outcome->collection->data); - } - } - - public function provideTests() - { - $testArgs = []; - - foreach (glob(__DIR__ . '/read-write-concern/operation/*.json') as $filename) { - $json = $this->decodeJson(file_get_contents($filename)); - $group = basename(dirname($filename)) . '/' . basename($filename, '.json'); - $runOn = $json->runOn ?? null; - $data = $json->data ?? []; - // phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps - $databaseName = $json->database_name ?? null; - $collectionName = $json->collection_name ?? null; - // phpcs:enable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps - - foreach ($json->tests as $test) { - $name = $group . ': ' . $test->description; - $testArgs[$name] = [$test, $runOn, $data, $databaseName, $collectionName]; - } - } - - return $testArgs; - } -} diff --git a/tests/SpecTests/read-write-concern/operation/default-write-concern-2.6.json b/tests/SpecTests/read-write-concern/operation/default-write-concern-2.6.json deleted file mode 100644 index c623298cd..000000000 --- a/tests/SpecTests/read-write-concern/operation/default-write-concern-2.6.json +++ /dev/null @@ -1,544 +0,0 @@ -{ - "data": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - } - ], - "collection_name": "default_write_concern_coll", - "database_name": "default_write_concern_db", - "runOn": [ - { - "minServerVersion": "2.6" - } - ], - "tests": [ - { - "description": "DeleteOne omits default write concern", - "operations": [ - { - "name": "deleteOne", - "object": "collection", - "collectionOptions": { - "writeConcern": {} - }, - "arguments": { - "filter": {} - }, - "result": { - "deletedCount": 1 - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "delete": "default_write_concern_coll", - "deletes": [ - { - "q": {}, - "limit": 1 - } - ], - "writeConcern": null - } - } - } - ] - }, - { - "description": "DeleteMany omits default write concern", - "operations": [ - { - "name": "deleteMany", - "object": "collection", - "collectionOptions": { - "writeConcern": {} - }, - "arguments": { - "filter": {} - }, - "result": { - "deletedCount": 2 - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "delete": "default_write_concern_coll", - "deletes": [ - { - "q": {}, - "limit": 0 - } - ], - "writeConcern": null - } - } - } - ] - }, - { - "description": "BulkWrite with all models omits default write concern", - "operations": [ - { - "name": "bulkWrite", - "object": "collection", - "collectionOptions": { - "writeConcern": {} - }, - "arguments": { - "ordered": true, - "requests": [ - { - "name": "deleteMany", - "arguments": { - "filter": {} - } - }, - { - "name": "insertOne", - "arguments": { - "document": { - "_id": 1 - } - } - }, - { - "name": "updateOne", - "arguments": { - "filter": { - "_id": 1 - }, - "update": { - "$set": { - "x": 1 - } - } - } - }, - { - "name": "insertOne", - "arguments": { - "document": { - "_id": 2 - } - } - }, - { - "name": "replaceOne", - "arguments": { - "filter": { - "_id": 1 - }, - "replacement": { - "x": 2 - } - } - }, - { - "name": "insertOne", - "arguments": { - "document": { - "_id": 3 - } - } - }, - { - "name": "updateMany", - "arguments": { - "filter": { - "_id": 1 - }, - "update": { - "$set": { - "x": 3 - } - } - } - }, - { - "name": "deleteOne", - "arguments": { - "filter": { - "_id": 3 - } - } - } - ] - } - } - ], - "outcome": { - "collection": { - "name": "default_write_concern_coll", - "data": [ - { - "_id": 1, - "x": 3 - }, - { - "_id": 2 - } - ] - } - }, - "expectations": [ - { - "command_started_event": { - "command": { - "delete": "default_write_concern_coll", - "deletes": [ - { - "q": {}, - "limit": 0 - } - ], - "writeConcern": null - } - } - }, - { - "command_started_event": { - "command": { - "insert": "default_write_concern_coll", - "documents": [ - { - "_id": 1 - } - ], - "writeConcern": null - } - } - }, - { - "command_started_event": { - "command": { - "update": "default_write_concern_coll", - "updates": [ - { - "q": { - "_id": 1 - }, - "u": { - "$set": { - "x": 1 - } - } - } - ], - "writeConcern": null - } - } - }, - { - "command_started_event": { - "command": { - "insert": "default_write_concern_coll", - "documents": [ - { - "_id": 2 - } - ], - "writeConcern": null - } - } - }, - { - "command_started_event": { - "command": { - "update": "default_write_concern_coll", - "updates": [ - { - "q": { - "_id": 1 - }, - "u": { - "x": 2 - } - } - ], - "writeConcern": null - } - } - }, - { - "command_started_event": { - "command": { - "insert": "default_write_concern_coll", - "documents": [ - { - "_id": 3 - } - ], - "writeConcern": null - } - } - }, - { - "command_started_event": { - "command": { - "update": "default_write_concern_coll", - "updates": [ - { - "q": { - "_id": 1 - }, - "u": { - "$set": { - "x": 3 - } - }, - "multi": true - } - ], - "writeConcern": null - } - } - }, - { - "command_started_event": { - "command": { - "delete": "default_write_concern_coll", - "deletes": [ - { - "q": { - "_id": 3 - }, - "limit": 1 - } - ], - "writeConcern": null - } - } - } - ] - }, - { - "description": "InsertOne and InsertMany omit default write concern", - "operations": [ - { - "name": "insertOne", - "object": "collection", - "collectionOptions": { - "writeConcern": {} - }, - "arguments": { - "document": { - "_id": 3 - } - } - }, - { - "name": "insertMany", - "object": "collection", - "collectionOptions": { - "writeConcern": {} - }, - "arguments": { - "documents": [ - { - "_id": 4 - }, - { - "_id": 5 - } - ] - } - } - ], - "outcome": { - "collection": { - "name": "default_write_concern_coll", - "data": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - }, - { - "_id": 3 - }, - { - "_id": 4 - }, - { - "_id": 5 - } - ] - } - }, - "expectations": [ - { - "command_started_event": { - "command": { - "insert": "default_write_concern_coll", - "documents": [ - { - "_id": 3 - } - ], - "writeConcern": null - } - } - }, - { - "command_started_event": { - "command": { - "insert": "default_write_concern_coll", - "documents": [ - { - "_id": 4 - }, - { - "_id": 5 - } - ], - "writeConcern": null - } - } - } - ] - }, - { - "description": "UpdateOne, UpdateMany, and ReplaceOne omit default write concern", - "operations": [ - { - "name": "updateOne", - "object": "collection", - "collectionOptions": { - "writeConcern": {} - }, - "arguments": { - "filter": { - "_id": 1 - }, - "update": { - "$set": { - "x": 1 - } - } - } - }, - { - "name": "updateMany", - "object": "collection", - "collectionOptions": { - "writeConcern": {} - }, - "arguments": { - "filter": { - "_id": 2 - }, - "update": { - "$set": { - "x": 2 - } - } - } - }, - { - "name": "replaceOne", - "object": "collection", - "collectionOptions": { - "writeConcern": {} - }, - "arguments": { - "filter": { - "_id": 2 - }, - "replacement": { - "x": 3 - } - } - } - ], - "outcome": { - "collection": { - "name": "default_write_concern_coll", - "data": [ - { - "_id": 1, - "x": 1 - }, - { - "_id": 2, - "x": 3 - } - ] - } - }, - "expectations": [ - { - "command_started_event": { - "command": { - "update": "default_write_concern_coll", - "updates": [ - { - "q": { - "_id": 1 - }, - "u": { - "$set": { - "x": 1 - } - } - } - ], - "writeConcern": null - } - } - }, - { - "command_started_event": { - "command": { - "update": "default_write_concern_coll", - "updates": [ - { - "q": { - "_id": 2 - }, - "u": { - "$set": { - "x": 2 - } - }, - "multi": true - } - ], - "writeConcern": null - } - } - }, - { - "command_started_event": { - "command": { - "update": "default_write_concern_coll", - "updates": [ - { - "q": { - "_id": 2 - }, - "u": { - "x": 3 - } - } - ], - "writeConcern": null - } - } - } - ] - } - ] -} diff --git a/tests/SpecTests/read-write-concern/operation/default-write-concern-3.2.json b/tests/SpecTests/read-write-concern/operation/default-write-concern-3.2.json deleted file mode 100644 index 04dd231f0..000000000 --- a/tests/SpecTests/read-write-concern/operation/default-write-concern-3.2.json +++ /dev/null @@ -1,125 +0,0 @@ -{ - "data": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - } - ], - "collection_name": "default_write_concern_coll", - "database_name": "default_write_concern_db", - "runOn": [ - { - "minServerVersion": "3.2" - } - ], - "tests": [ - { - "description": "findAndModify operations omit default write concern", - "operations": [ - { - "name": "findOneAndUpdate", - "object": "collection", - "collectionOptions": { - "writeConcern": {} - }, - "arguments": { - "filter": { - "_id": 1 - }, - "update": { - "$set": { - "x": 1 - } - } - } - }, - { - "name": "findOneAndReplace", - "object": "collection", - "collectionOptions": { - "writeConcern": {} - }, - "arguments": { - "filter": { - "_id": 2 - }, - "replacement": { - "x": 2 - } - } - }, - { - "name": "findOneAndDelete", - "object": "collection", - "collectionOptions": { - "writeConcern": {} - }, - "arguments": { - "filter": { - "_id": 2 - } - } - } - ], - "outcome": { - "collection": { - "name": "default_write_concern_coll", - "data": [ - { - "_id": 1, - "x": 1 - } - ] - } - }, - "expectations": [ - { - "command_started_event": { - "command": { - "findAndModify": "default_write_concern_coll", - "query": { - "_id": 1 - }, - "update": { - "$set": { - "x": 1 - } - }, - "writeConcern": null - } - } - }, - { - "command_started_event": { - "command": { - "findAndModify": "default_write_concern_coll", - "query": { - "_id": 2 - }, - "update": { - "x": 2 - }, - "writeConcern": null - } - } - }, - { - "command_started_event": { - "command": { - "findAndModify": "default_write_concern_coll", - "query": { - "_id": 2 - }, - "remove": true, - "writeConcern": null - } - } - } - ] - } - ] -} diff --git a/tests/SpecTests/read-write-concern/operation/default-write-concern-3.4.json b/tests/SpecTests/read-write-concern/operation/default-write-concern-3.4.json deleted file mode 100644 index 6519f6f08..000000000 --- a/tests/SpecTests/read-write-concern/operation/default-write-concern-3.4.json +++ /dev/null @@ -1,216 +0,0 @@ -{ - "data": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - } - ], - "collection_name": "default_write_concern_coll", - "database_name": "default_write_concern_db", - "runOn": [ - { - "minServerVersion": "3.4" - } - ], - "tests": [ - { - "description": "Aggregate with $out omits default write concern", - "operations": [ - { - "object": "collection", - "collectionOptions": { - "writeConcern": {} - }, - "name": "aggregate", - "arguments": { - "pipeline": [ - { - "$match": { - "_id": { - "$gt": 1 - } - } - }, - { - "$out": "other_collection_name" - } - ] - } - } - ], - "outcome": { - "collection": { - "name": "other_collection_name", - "data": [ - { - "_id": 2, - "x": 22 - } - ] - } - }, - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "default_write_concern_coll", - "pipeline": [ - { - "$match": { - "_id": { - "$gt": 1 - } - } - }, - { - "$out": "other_collection_name" - } - ], - "writeConcern": null - } - } - } - ] - }, - { - "description": "RunCommand with a write command omits default write concern (runCommand should never inherit write concern)", - "operations": [ - { - "object": "database", - "databaseOptions": { - "writeConcern": {} - }, - "name": "runCommand", - "command_name": "delete", - "arguments": { - "command": { - "delete": "default_write_concern_coll", - "deletes": [ - { - "q": {}, - "limit": 1 - } - ] - } - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "delete": "default_write_concern_coll", - "deletes": [ - { - "q": {}, - "limit": 1 - } - ], - "writeConcern": null - } - } - } - ] - }, - { - "description": "CreateIndex and dropIndex omits default write concern", - "operations": [ - { - "object": "collection", - "collectionOptions": { - "writeConcern": {} - }, - "name": "createIndex", - "arguments": { - "keys": { - "x": 1 - } - } - }, - { - "object": "collection", - "collectionOptions": { - "writeConcern": {} - }, - "name": "dropIndex", - "arguments": { - "name": "x_1" - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "createIndexes": "default_write_concern_coll", - "indexes": [ - { - "name": "x_1", - "key": { - "x": 1 - } - } - ], - "writeConcern": null - } - } - }, - { - "command_started_event": { - "command": { - "dropIndexes": "default_write_concern_coll", - "index": "x_1", - "writeConcern": null - } - } - } - ] - }, - { - "description": "MapReduce omits default write concern", - "operations": [ - { - "name": "mapReduce", - "object": "collection", - "collectionOptions": { - "writeConcern": {} - }, - "arguments": { - "map": { - "$code": "function inc() { return emit(0, this.x + 1) }" - }, - "reduce": { - "$code": "function sum(key, values) { return values.reduce((acc, x) => acc + x); }" - }, - "out": { - "inline": 1 - } - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "mapReduce": "default_write_concern_coll", - "map": { - "$code": "function inc() { return emit(0, this.x + 1) }" - }, - "reduce": { - "$code": "function sum(key, values) { return values.reduce((acc, x) => acc + x); }" - }, - "out": { - "inline": 1 - }, - "writeConcern": null - } - } - } - ] - } - ] -} diff --git a/tests/SpecTests/read-write-concern/operation/default-write-concern-4.2.json b/tests/SpecTests/read-write-concern/operation/default-write-concern-4.2.json deleted file mode 100644 index fef192d1a..000000000 --- a/tests/SpecTests/read-write-concern/operation/default-write-concern-4.2.json +++ /dev/null @@ -1,87 +0,0 @@ -{ - "data": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - } - ], - "collection_name": "default_write_concern_coll", - "database_name": "default_write_concern_db", - "runOn": [ - { - "minServerVersion": "4.2" - } - ], - "tests": [ - { - "description": "Aggregate with $merge omits default write concern", - "operations": [ - { - "object": "collection", - "databaseOptions": { - "writeConcern": {} - }, - "collectionOptions": { - "writeConcern": {} - }, - "name": "aggregate", - "arguments": { - "pipeline": [ - { - "$match": { - "_id": { - "$gt": 1 - } - } - }, - { - "$merge": { - "into": "other_collection_name" - } - } - ] - } - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "default_write_concern_coll", - "pipeline": [ - { - "$match": { - "_id": { - "$gt": 1 - } - } - }, - { - "$merge": { - "into": "other_collection_name" - } - } - ], - "writeConcern": null - } - } - } - ], - "outcome": { - "collection": { - "name": "other_collection_name", - "data": [ - { - "_id": 2, - "x": 22 - } - ] - } - } - } - ] -} From 7b5edb5ee89af87865ac406db478075930a6e28a Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Mon, 11 Mar 2024 22:34:15 -0400 Subject: [PATCH 2/2] PHPLIB-1409: Convert default write concern tests to unified test format Synced with mongodb/specifications@bfb6a841819e117aa7f066beae4cfa9da7690a1b --- tests/UnifiedSpecTests/UnifiedSpecTest.php | 11 + .../default-write-concern-2.6.json | 636 ++++++++++++++++++ .../default-write-concern-3.2.json | 164 +++++ .../default-write-concern-3.4.json | 268 ++++++++ .../default-write-concern-4.2.json | 125 ++++ 5 files changed, 1204 insertions(+) create mode 100644 tests/UnifiedSpecTests/read-write-concern/default-write-concern-2.6.json create mode 100644 tests/UnifiedSpecTests/read-write-concern/default-write-concern-3.2.json create mode 100644 tests/UnifiedSpecTests/read-write-concern/default-write-concern-3.4.json create mode 100644 tests/UnifiedSpecTests/read-write-concern/default-write-concern-4.2.json diff --git a/tests/UnifiedSpecTests/UnifiedSpecTest.php b/tests/UnifiedSpecTests/UnifiedSpecTest.php index 3fa8054fa..59d3d8b94 100644 --- a/tests/UnifiedSpecTests/UnifiedSpecTest.php +++ b/tests/UnifiedSpecTests/UnifiedSpecTest.php @@ -311,6 +311,17 @@ public function provideLoadBalancers() return $this->provideTests(__DIR__ . '/load-balancers/*.json'); } + /** @dataProvider provideReadWriteConcernTests */ + public function testReadWriteConcern(UnifiedTestCase $test): void + { + self::$runner->run($test); + } + + public function provideReadWriteConcernTests() + { + return $this->provideTests(__DIR__ . '/read-write-concern/*.json'); + } + /** @dataProvider provideRetryableReadsTests */ public function testRetryableReads(UnifiedTestCase $test): void { diff --git a/tests/UnifiedSpecTests/read-write-concern/default-write-concern-2.6.json b/tests/UnifiedSpecTests/read-write-concern/default-write-concern-2.6.json new file mode 100644 index 000000000..0d8f9c98a --- /dev/null +++ b/tests/UnifiedSpecTests/read-write-concern/default-write-concern-2.6.json @@ -0,0 +1,636 @@ +{ + "description": "default-write-concern-2.6", + "schemaVersion": "1.0", + "runOnRequirements": [ + { + "minServerVersion": "2.6" + } + ], + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "default-write-concern-tests", + "databaseOptions": { + "writeConcern": {} + } + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll", + "collectionOptions": { + "writeConcern": {} + } + } + } + ], + "initialData": [ + { + "collectionName": "coll", + "databaseName": "default-write-concern-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + ], + "tests": [ + { + "description": "DeleteOne omits default write concern", + "operations": [ + { + "name": "deleteOne", + "object": "collection0", + "arguments": { + "filter": {} + }, + "expectResult": { + "deletedCount": 1 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "delete": "coll", + "deletes": [ + { + "q": {}, + "limit": 1 + } + ], + "writeConcern": { + "$$exists": false + } + } + } + } + ] + } + ] + }, + { + "description": "DeleteMany omits default write concern", + "operations": [ + { + "name": "deleteMany", + "object": "collection0", + "arguments": { + "filter": {} + }, + "expectResult": { + "deletedCount": 2 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "delete": "coll", + "deletes": [ + { + "q": {}, + "limit": 0 + } + ], + "writeConcern": { + "$$exists": false + } + } + } + } + ] + } + ] + }, + { + "description": "BulkWrite with all models omits default write concern", + "operations": [ + { + "name": "bulkWrite", + "object": "collection0", + "arguments": { + "ordered": true, + "requests": [ + { + "deleteMany": { + "filter": {} + } + }, + { + "insertOne": { + "document": { + "_id": 1 + } + } + }, + { + "updateOne": { + "filter": { + "_id": 1 + }, + "update": { + "$set": { + "x": 1 + } + } + } + }, + { + "insertOne": { + "document": { + "_id": 2 + } + } + }, + { + "replaceOne": { + "filter": { + "_id": 1 + }, + "replacement": { + "x": 2 + } + } + }, + { + "insertOne": { + "document": { + "_id": 3 + } + } + }, + { + "updateMany": { + "filter": { + "_id": 1 + }, + "update": { + "$set": { + "x": 3 + } + } + } + }, + { + "deleteOne": { + "filter": { + "_id": 3 + } + } + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "delete": "coll", + "deletes": [ + { + "q": {}, + "limit": 0 + } + ], + "writeConcern": { + "$$exists": false + } + } + } + }, + { + "commandStartedEvent": { + "command": { + "insert": "coll", + "documents": [ + { + "_id": 1 + } + ], + "writeConcern": { + "$$exists": false + } + } + } + }, + { + "commandStartedEvent": { + "command": { + "update": "coll", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "$set": { + "x": 1 + } + }, + "upsert": { + "$$unsetOrMatches": false + }, + "multi": { + "$$unsetOrMatches": false + } + } + ], + "writeConcern": { + "$$exists": false + } + } + } + }, + { + "commandStartedEvent": { + "command": { + "insert": "coll", + "documents": [ + { + "_id": 2 + } + ], + "writeConcern": { + "$$exists": false + } + } + } + }, + { + "commandStartedEvent": { + "command": { + "update": "coll", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "x": 2 + }, + "upsert": { + "$$unsetOrMatches": false + }, + "multi": { + "$$unsetOrMatches": false + } + } + ], + "writeConcern": { + "$$exists": false + } + } + } + }, + { + "commandStartedEvent": { + "command": { + "insert": "coll", + "documents": [ + { + "_id": 3 + } + ], + "writeConcern": { + "$$exists": false + } + } + } + }, + { + "commandStartedEvent": { + "command": { + "update": "coll", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "$set": { + "x": 3 + } + }, + "multi": true, + "upsert": { + "$$unsetOrMatches": false + } + } + ], + "writeConcern": { + "$$exists": false + } + } + } + }, + { + "commandStartedEvent": { + "command": { + "delete": "coll", + "deletes": [ + { + "q": { + "_id": 3 + }, + "limit": 1 + } + ], + "writeConcern": { + "$$exists": false + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll", + "databaseName": "default-write-concern-tests", + "documents": [ + { + "_id": 1, + "x": 3 + }, + { + "_id": 2 + } + ] + } + ] + }, + { + "description": "InsertOne and InsertMany omit default write concern", + "operations": [ + { + "name": "insertOne", + "object": "collection0", + "arguments": { + "document": { + "_id": 3 + } + } + }, + { + "name": "insertMany", + "object": "collection0", + "arguments": { + "documents": [ + { + "_id": 4 + }, + { + "_id": 5 + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "insert": "coll", + "documents": [ + { + "_id": 3 + } + ], + "writeConcern": { + "$$exists": false + } + } + } + }, + { + "commandStartedEvent": { + "command": { + "insert": "coll", + "documents": [ + { + "_id": 4 + }, + { + "_id": 5 + } + ], + "writeConcern": { + "$$exists": false + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll", + "databaseName": "default-write-concern-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3 + }, + { + "_id": 4 + }, + { + "_id": 5 + } + ] + } + ] + }, + { + "description": "UpdateOne, UpdateMany, and ReplaceOne omit default write concern", + "operations": [ + { + "name": "updateOne", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "update": { + "$set": { + "x": 1 + } + } + } + }, + { + "name": "updateMany", + "object": "collection0", + "arguments": { + "filter": { + "_id": 2 + }, + "update": { + "$set": { + "x": 2 + } + } + } + }, + { + "name": "replaceOne", + "object": "collection0", + "arguments": { + "filter": { + "_id": 2 + }, + "replacement": { + "x": 3 + } + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "update": "coll", + "updates": [ + { + "q": { + "_id": 1 + }, + "u": { + "$set": { + "x": 1 + } + }, + "upsert": { + "$$unsetOrMatches": false + }, + "multi": { + "$$unsetOrMatches": false + } + } + ], + "writeConcern": { + "$$exists": false + } + } + } + }, + { + "commandStartedEvent": { + "command": { + "update": "coll", + "updates": [ + { + "q": { + "_id": 2 + }, + "u": { + "$set": { + "x": 2 + } + }, + "multi": true, + "upsert": { + "$$unsetOrMatches": false + } + } + ], + "writeConcern": { + "$$exists": false + } + } + } + }, + { + "commandStartedEvent": { + "command": { + "update": "coll", + "updates": [ + { + "q": { + "_id": 2 + }, + "u": { + "x": 3 + }, + "upsert": { + "$$unsetOrMatches": false + }, + "multi": { + "$$unsetOrMatches": false + } + } + ], + "writeConcern": { + "$$exists": false + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll", + "databaseName": "default-write-concern-tests", + "documents": [ + { + "_id": 1, + "x": 1 + }, + { + "_id": 2, + "x": 3 + } + ] + } + ] + } + ] +} diff --git a/tests/UnifiedSpecTests/read-write-concern/default-write-concern-3.2.json b/tests/UnifiedSpecTests/read-write-concern/default-write-concern-3.2.json new file mode 100644 index 000000000..166a18491 --- /dev/null +++ b/tests/UnifiedSpecTests/read-write-concern/default-write-concern-3.2.json @@ -0,0 +1,164 @@ +{ + "description": "default-write-concern-3.2", + "schemaVersion": "1.0", + "runOnRequirements": [ + { + "minServerVersion": "3.2" + } + ], + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "default-write-concern-tests", + "databaseOptions": { + "writeConcern": {} + } + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll", + "collectionOptions": { + "writeConcern": {} + } + } + } + ], + "initialData": [ + { + "collectionName": "coll", + "databaseName": "default-write-concern-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + ], + "tests": [ + { + "description": "findAndModify operations omit default write concern", + "operations": [ + { + "name": "findOneAndUpdate", + "object": "collection0", + "arguments": { + "filter": { + "_id": 1 + }, + "update": { + "$set": { + "x": 1 + } + } + } + }, + { + "name": "findOneAndReplace", + "object": "collection0", + "arguments": { + "filter": { + "_id": 2 + }, + "replacement": { + "x": 2 + } + } + }, + { + "name": "findOneAndDelete", + "object": "collection0", + "arguments": { + "filter": { + "_id": 2 + } + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "findAndModify": "coll", + "query": { + "_id": 1 + }, + "update": { + "$set": { + "x": 1 + } + }, + "writeConcern": { + "$$exists": false + } + } + } + }, + { + "commandStartedEvent": { + "command": { + "findAndModify": "coll", + "query": { + "_id": 2 + }, + "update": { + "x": 2 + }, + "writeConcern": { + "$$exists": false + } + } + } + }, + { + "commandStartedEvent": { + "command": { + "findAndModify": "coll", + "query": { + "_id": 2 + }, + "remove": true, + "writeConcern": { + "$$exists": false + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "coll", + "databaseName": "default-write-concern-tests", + "documents": [ + { + "_id": 1, + "x": 1 + } + ] + } + ] + } + ] +} diff --git a/tests/UnifiedSpecTests/read-write-concern/default-write-concern-3.4.json b/tests/UnifiedSpecTests/read-write-concern/default-write-concern-3.4.json new file mode 100644 index 000000000..e3add9876 --- /dev/null +++ b/tests/UnifiedSpecTests/read-write-concern/default-write-concern-3.4.json @@ -0,0 +1,268 @@ +{ + "description": "default-write-concern-3.4", + "schemaVersion": "1.0", + "runOnRequirements": [ + { + "minServerVersion": "3.4" + } + ], + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "default-write-concern-tests", + "databaseOptions": { + "writeConcern": {} + } + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll", + "collectionOptions": { + "writeConcern": {} + } + } + } + ], + "initialData": [ + { + "collectionName": "coll", + "databaseName": "default-write-concern-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + ], + "tests": [ + { + "description": "Aggregate with $out omits default write concern", + "operations": [ + { + "object": "collection0", + "name": "aggregate", + "arguments": { + "pipeline": [ + { + "$match": { + "_id": { + "$gt": 1 + } + } + }, + { + "$out": "other_collection_name" + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "aggregate": "coll", + "pipeline": [ + { + "$match": { + "_id": { + "$gt": 1 + } + } + }, + { + "$out": "other_collection_name" + } + ], + "writeConcern": { + "$$exists": false + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "other_collection_name", + "databaseName": "default-write-concern-tests", + "documents": [ + { + "_id": 2, + "x": 22 + } + ] + } + ] + }, + { + "description": "RunCommand with a write command omits default write concern (runCommand should never inherit write concern)", + "operations": [ + { + "object": "database0", + "name": "runCommand", + "arguments": { + "command": { + "delete": "coll", + "deletes": [ + { + "q": {}, + "limit": 1 + } + ] + }, + "commandName": "delete" + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "delete": "coll", + "deletes": [ + { + "q": {}, + "limit": 1 + } + ], + "writeConcern": { + "$$exists": false + } + } + } + } + ] + } + ] + }, + { + "description": "CreateIndex and dropIndex omits default write concern", + "operations": [ + { + "object": "collection0", + "name": "createIndex", + "arguments": { + "keys": { + "x": 1 + } + } + }, + { + "object": "collection0", + "name": "dropIndex", + "arguments": { + "name": "x_1" + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "createIndexes": "coll", + "indexes": [ + { + "name": "x_1", + "key": { + "x": 1 + } + } + ], + "writeConcern": { + "$$exists": false + } + } + } + }, + { + "commandStartedEvent": { + "command": { + "dropIndexes": "coll", + "index": "x_1", + "writeConcern": { + "$$exists": false + } + } + } + } + ] + } + ] + }, + { + "description": "MapReduce omits default write concern", + "operations": [ + { + "name": "mapReduce", + "object": "collection0", + "arguments": { + "map": { + "$code": "function inc() { return emit(0, this.x + 1) }" + }, + "reduce": { + "$code": "function sum(key, values) { return values.reduce((acc, x) => acc + x); }" + }, + "out": { + "inline": 1 + } + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "mapReduce": "coll", + "map": { + "$code": "function inc() { return emit(0, this.x + 1) }" + }, + "reduce": { + "$code": "function sum(key, values) { return values.reduce((acc, x) => acc + x); }" + }, + "out": { + "inline": 1 + }, + "writeConcern": { + "$$exists": false + } + } + } + } + ] + } + ] + } + ] +} diff --git a/tests/UnifiedSpecTests/read-write-concern/default-write-concern-4.2.json b/tests/UnifiedSpecTests/read-write-concern/default-write-concern-4.2.json new file mode 100644 index 000000000..e8bb78d91 --- /dev/null +++ b/tests/UnifiedSpecTests/read-write-concern/default-write-concern-4.2.json @@ -0,0 +1,125 @@ +{ + "description": "default-write-concern-4.2", + "schemaVersion": "1.0", + "runOnRequirements": [ + { + "minServerVersion": "4.2" + } + ], + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "default-write-concern-tests", + "databaseOptions": { + "writeConcern": {} + } + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll", + "collectionOptions": { + "writeConcern": {} + } + } + } + ], + "initialData": [ + { + "collectionName": "coll", + "databaseName": "default-write-concern-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ] + } + ], + "tests": [ + { + "description": "Aggregate with $merge omits default write concern", + "operations": [ + { + "object": "collection0", + "name": "aggregate", + "arguments": { + "pipeline": [ + { + "$match": { + "_id": { + "$gt": 1 + } + } + }, + { + "$merge": { + "into": "other_collection_name" + } + } + ] + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "aggregate": "coll", + "pipeline": [ + { + "$match": { + "_id": { + "$gt": 1 + } + } + }, + { + "$merge": { + "into": "other_collection_name" + } + } + ], + "writeConcern": { + "$$exists": false + } + } + } + } + ] + } + ], + "outcome": [ + { + "collectionName": "other_collection_name", + "databaseName": "default-write-concern-tests", + "documents": [ + { + "_id": 2, + "x": 22 + } + ] + } + ] + } + ] +}