From 2e44de699791a8989424bb1f1383e65260a0270b Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Wed, 11 May 2022 15:22:28 +0200 Subject: [PATCH 1/9] feat(NODE-4079): estimated document count uses count --- src/operations/estimated_document_count.ts | 5 +- .../crud/unified/estimatedDocumentCount.json | 371 ++++-------------- .../crud/unified/estimatedDocumentCount.yml | 184 +++------ .../crud-api-version-1-strict.json | 26 +- .../crud-api-version-1-strict.yml | 10 +- .../versioned-api/crud-api-version-1.json | 28 +- .../spec/versioned-api/crud-api-version-1.yml | 12 +- 7 files changed, 168 insertions(+), 468 deletions(-) diff --git a/src/operations/estimated_document_count.ts b/src/operations/estimated_document_count.ts index 6513e5795bd..45084a3c599 100644 --- a/src/operations/estimated_document_count.ts +++ b/src/operations/estimated_document_count.ts @@ -36,9 +36,8 @@ export class EstimatedDocumentCountOperation extends CommandOperation { if (maxWireVersion(server) < 12) { return this.executeLegacy(server, session, callback); } - const pipeline = [{ $collStats: { count: {} } }, { $group: { _id: 1, n: { $sum: '$count' } } }]; - const cmd: Document = { aggregate: this.collectionName, pipeline, cursor: {} }; + const cmd: Document = { count: this.collectionName }; if (typeof this.options.maxTimeMS === 'number') { cmd.maxTimeMS = this.options.maxTimeMS; @@ -50,7 +49,7 @@ export class EstimatedDocumentCountOperation extends CommandOperation { return; } - callback(undefined, response?.cursor?.firstBatch[0]?.n || 0); + callback(undefined, response?.n || 0); }); } diff --git a/test/spec/crud/unified/estimatedDocumentCount.json b/test/spec/crud/unified/estimatedDocumentCount.json index bcd66ea9543..1b650c1cb6c 100644 --- a/test/spec/crud/unified/estimatedDocumentCount.json +++ b/test/spec/crud/unified/estimatedDocumentCount.json @@ -34,6 +34,13 @@ "database": "database0", "collectionName": "coll1" } + }, + { + "collection": { + "id": "collection0View", + "database": "database0", + "collectionName": "coll0view" + } } ], "initialData": [ @@ -58,12 +65,7 @@ ], "tests": [ { - "description": "estimatedDocumentCount uses $collStats on 4.9.0 or greater", - "runOnRequirements": [ - { - "minServerVersion": "4.9.0" - } - ], + "description": "estimatedDocumentCount always uses count", "operations": [ { "name": "estimatedDocumentCount", @@ -78,24 +80,9 @@ { "commandStartedEvent": { "command": { - "aggregate": "coll0", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] + "count": "coll0" }, - "commandName": "aggregate", + "commandName": "count", "databaseName": "edc-tests" } } @@ -104,12 +91,7 @@ ] }, { - "description": "estimatedDocumentCount with maxTimeMS on 4.9.0 or greater", - "runOnRequirements": [ - { - "minServerVersion": "4.9.0" - } - ], + "description": "estimatedDocumentCount with maxTimeMS", "operations": [ { "name": "estimatedDocumentCount", @@ -127,25 +109,10 @@ { "commandStartedEvent": { "command": { - "aggregate": "coll0", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ], + "count": "coll0", "maxTimeMS": 6000 }, - "commandName": "aggregate", + "commandName": "count", "databaseName": "edc-tests" } } @@ -154,12 +121,7 @@ ] }, { - "description": "estimatedDocumentCount on non-existent collection on 4.9.0 or greater", - "runOnRequirements": [ - { - "minServerVersion": "4.9.0" - } - ], + "description": "estimatedDocumentCount on non-existent collection", "operations": [ { "name": "estimatedDocumentCount", @@ -174,24 +136,9 @@ { "commandStartedEvent": { "command": { - "aggregate": "coll1", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] + "count": "coll1" }, - "commandName": "aggregate", + "commandName": "count", "databaseName": "edc-tests" } } @@ -200,78 +147,21 @@ ] }, { - "description": "estimatedDocumentCount errors correctly on 4.9.0 or greater--command error", + "description": "estimatedDocumentCount errors correctly--command error", "runOnRequirements": [ { - "minServerVersion": "4.9.0" - } - ], - "operations": [ - { - "name": "failPoint", - "object": "testRunner", - "arguments": { - "client": "client0", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 8 - } - } - } + "minServerVersion": "4.0.0", + "topologies": [ + "single", + "replicaset" + ] }, { - "name": "estimatedDocumentCount", - "object": "collection0", - "expectError": { - "errorCode": 8 - } - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "aggregate": "coll0", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "commandName": "aggregate", - "databaseName": "edc-tests" - } - } + "minServerVersion": "4.2.0", + "topologies": [ + "sharded" ] } - ] - }, - { - "description": "estimatedDocumentCount errors correctly on 4.9.0 or greater--socket error", - "runOnRequirements": [ - { - "minServerVersion": "4.9.0" - } ], "operations": [ { @@ -286,9 +176,9 @@ }, "data": { "failCommands": [ - "aggregate" + "count" ], - "closeConnection": true + "errorCode": 8 } } } @@ -297,56 +187,10 @@ "name": "estimatedDocumentCount", "object": "collection0", "expectError": { - "isError": true + "errorCode": 8 } } ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "aggregate": "coll0", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "commandName": "aggregate", - "databaseName": "edc-tests" - } - } - ] - } - ] - }, - { - "description": "estimatedDocumentCount uses count on less than 4.9.0", - "runOnRequirements": [ - { - "maxServerVersion": "4.8.99" - } - ], - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection0", - "expectResult": 3 - } - ], "expectEvents": [ { "client": "client0", @@ -365,77 +209,10 @@ ] }, { - "description": "estimatedDocumentCount with maxTimeMS on less than 4.9.0", - "runOnRequirements": [ - { - "maxServerVersion": "4.8.99" - } - ], - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection0", - "arguments": { - "maxTimeMS": 6000 - }, - "expectResult": 3 - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "count": "coll0", - "maxTimeMS": 6000 - }, - "commandName": "count", - "databaseName": "edc-tests" - } - } - ] - } - ] - }, - { - "description": "estimatedDocumentCount on non-existent collection on less than 4.9.0", - "runOnRequirements": [ - { - "maxServerVersion": "4.8.99" - } - ], - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection1", - "expectResult": 0 - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "count": "coll1" - }, - "commandName": "count", - "databaseName": "edc-tests" - } - } - ] - } - ] - }, - { - "description": "estimatedDocumentCount errors correctly on less than 4.9.0--command error", + "description": "estimatedDocumentCount errors correctly--socket error", "runOnRequirements": [ { "minServerVersion": "4.0.0", - "maxServerVersion": "4.8.99", "topologies": [ "single", "replicaset" @@ -443,7 +220,6 @@ }, { "minServerVersion": "4.2.0", - "maxServerVersion": "4.8.99", "topologies": [ "sharded" ] @@ -464,7 +240,7 @@ "failCommands": [ "count" ], - "errorCode": 8 + "closeConnection": true } } } @@ -473,7 +249,7 @@ "name": "estimatedDocumentCount", "object": "collection0", "expectError": { - "errorCode": 8 + "isError": true } } ], @@ -495,50 +271,41 @@ ] }, { - "description": "estimatedDocumentCount errors correctly on less than 4.9.0--socket error", + "description": "estimatedDocumentCount works correctly on views", "runOnRequirements": [ { - "minServerVersion": "4.0.0", - "maxServerVersion": "4.8.99", - "topologies": [ - "single", - "replicaset" - ] - }, - { - "minServerVersion": "4.2.0", - "maxServerVersion": "4.8.99", - "topologies": [ - "sharded" - ] + "minServerVersion": "3.4.0" } ], "operations": [ { - "name": "failPoint", - "object": "testRunner", + "name": "dropCollection", + "object": "database0", "arguments": { - "client": "client0", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "count" - ], - "closeConnection": true + "collection": "coll0view" + } + }, + { + "name": "createCollection", + "object": "database0", + "arguments": { + "collection": "coll0view", + "viewOn": "coll0", + "pipeline": [ + { + "$match": { + "_id": { + "$gt": 1 + } + } } - } + ] } }, { "name": "estimatedDocumentCount", - "object": "collection0", - "expectError": { - "isError": true - } + "object": "collection0View", + "expectResult": 2 } ], "expectEvents": [ @@ -548,7 +315,35 @@ { "commandStartedEvent": { "command": { - "count": "coll0" + "drop": "coll0view" + }, + "commandName": "drop", + "databaseName": "edc-tests" + } + }, + { + "commandStartedEvent": { + "command": { + "create": "coll0view", + "viewOn": "coll0", + "pipeline": [ + { + "$match": { + "_id": { + "$gt": 1 + } + } + } + ] + }, + "commandName": "create", + "databaseName": "edc-tests" + } + }, + { + "commandStartedEvent": { + "command": { + "count": "coll0view" }, "commandName": "count", "databaseName": "edc-tests" diff --git a/test/spec/crud/unified/estimatedDocumentCount.yml b/test/spec/crud/unified/estimatedDocumentCount.yml index c3286ec176e..12f33cc7e51 100644 --- a/test/spec/crud/unified/estimatedDocumentCount.yml +++ b/test/spec/crud/unified/estimatedDocumentCount.yml @@ -21,6 +21,10 @@ createEntities: id: &collection1 collection1 database: *database0 collectionName: &collection1Name coll1 + - collection: + id: &collection0View collection0View + database: *database0 + collectionName: &collection0ViewName coll0view initialData: - collectionName: *collection0Name @@ -31,129 +35,7 @@ initialData: - { _id: 3, x: 33 } tests: - - description: "estimatedDocumentCount uses $collStats on 4.9.0 or greater" - runOnRequirements: - - minServerVersion: "4.9.0" - operations: - - name: estimatedDocumentCount - object: *collection0 - expectResult: 3 - expectEvents: - - client: *client0 - events: - - commandStartedEvent: - command: - aggregate: *collection0Name - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} - commandName: aggregate - databaseName: *database0Name - - - description: "estimatedDocumentCount with maxTimeMS on 4.9.0 or greater" - runOnRequirements: - - minServerVersion: "4.9.0" - operations: - - name: estimatedDocumentCount - object: *collection0 - arguments: - maxTimeMS: 6000 - expectResult: 3 - expectEvents: - - client: *client0 - events: - - commandStartedEvent: - command: - aggregate: *collection0Name - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} - maxTimeMS: 6000 - commandName: aggregate - databaseName: *database0Name - - - description: "estimatedDocumentCount on non-existent collection on 4.9.0 or greater" - runOnRequirements: - - minServerVersion: "4.9.0" - operations: - - name: estimatedDocumentCount - object: *collection1 - expectResult: 0 - expectEvents: - - client: *client0 - events: - - commandStartedEvent: - command: - aggregate: *collection1Name - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} - commandName: aggregate - databaseName: *database0Name - - - description: "estimatedDocumentCount errors correctly on 4.9.0 or greater--command error" - runOnRequirements: - - minServerVersion: "4.9.0" - operations: - - name: failPoint - object: testRunner - arguments: - client: *client0 - failPoint: - configureFailPoint: failCommand - mode: { times: 1 } - data: - failCommands: [ aggregate ] - errorCode: 8 # UnknownError - - name: estimatedDocumentCount - object: *collection0 - expectError: - errorCode: 8 # UnknownError - expectEvents: - - client: *client0 - events: - - commandStartedEvent: - command: - aggregate: *collection0Name - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} - commandName: aggregate - databaseName: *database0Name - - - description: "estimatedDocumentCount errors correctly on 4.9.0 or greater--socket error" - runOnRequirements: - - minServerVersion: "4.9.0" - operations: - - name: failPoint - object: testRunner - arguments: - client: *client0 - failPoint: - configureFailPoint: failCommand - mode: { times: 1 } - data: - failCommands: [ aggregate ] - closeConnection: true - - name: estimatedDocumentCount - object: *collection0 - expectError: - isError: true - expectEvents: - - client: *client0 - events: - - commandStartedEvent: - command: - aggregate: *collection0Name - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} - commandName: aggregate - databaseName: *database0Name - - - description: "estimatedDocumentCount uses count on less than 4.9.0" - runOnRequirements: - - maxServerVersion: "4.8.99" + - description: "estimatedDocumentCount always uses count" operations: - name: estimatedDocumentCount object: *collection0 @@ -167,9 +49,7 @@ tests: commandName: count databaseName: *database0Name - - description: "estimatedDocumentCount with maxTimeMS on less than 4.9.0" - runOnRequirements: - - maxServerVersion: "4.8.99" + - description: "estimatedDocumentCount with maxTimeMS" operations: - name: estimatedDocumentCount object: *collection0 @@ -186,9 +66,7 @@ tests: commandName: count databaseName: *database0Name - - description: "estimatedDocumentCount on non-existent collection on less than 4.9.0" - runOnRequirements: - - maxServerVersion: "4.8.99" + - description: "estimatedDocumentCount on non-existent collection" operations: - name: estimatedDocumentCount object: *collection1 @@ -202,13 +80,11 @@ tests: commandName: count databaseName: *database0Name - - description: "estimatedDocumentCount errors correctly on less than 4.9.0--command error" + - description: "estimatedDocumentCount errors correctly--command error" runOnRequirements: - minServerVersion: "4.0.0" - maxServerVersion: "4.8.99" topologies: [ single, replicaset ] - minServerVersion: "4.2.0" - maxServerVersion: "4.8.99" topologies: [ sharded ] operations: - name: failPoint @@ -234,13 +110,11 @@ tests: commandName: count databaseName: *database0Name - - description: "estimatedDocumentCount errors correctly on less than 4.9.0--socket error" + - description: "estimatedDocumentCount errors correctly--socket error" runOnRequirements: - minServerVersion: "4.0.0" - maxServerVersion: "4.8.99" topologies: [ single, replicaset ] - minServerVersion: "4.2.0" - maxServerVersion: "4.8.99" topologies: [ sharded ] operations: - name: failPoint @@ -265,3 +139,43 @@ tests: count: *collection0Name commandName: count databaseName: *database0Name + + - description: "estimatedDocumentCount works correctly on views" + # viewOn option was added to the create command in 3.4 + runOnRequirements: + - minServerVersion: "3.4.0" + operations: + - name: dropCollection + object: *database0 + arguments: + collection: *collection0ViewName + - name: createCollection + object: *database0 + arguments: + collection: *collection0ViewName + viewOn: *collection0Name + pipeline: &pipeline + - { $match: { _id: { $gt: 1 } } } + - name: estimatedDocumentCount + object: *collection0View + expectResult: 2 + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + drop: *collection0ViewName + commandName: drop + databaseName: *database0Name + - commandStartedEvent: + command: + create: *collection0ViewName + viewOn: *collection0Name + pipeline: *pipeline + commandName: create + databaseName: *database0Name + - commandStartedEvent: + command: + count: *collection0ViewName + commandName: count + databaseName: *database0Name diff --git a/test/spec/versioned-api/crud-api-version-1-strict.json b/test/spec/versioned-api/crud-api-version-1-strict.json index 29a0ec4e3bf..c1c8ecce01f 100644 --- a/test/spec/versioned-api/crud-api-version-1-strict.json +++ b/test/spec/versioned-api/crud-api-version-1-strict.json @@ -613,6 +613,15 @@ }, { "description": "estimatedDocumentCount appends declared API version", + "runOnRequirements": [ + { + "minServerVersion": "5.0.9", + "maxServerVersion": "5.0.99" + }, + { + "minServerVersion": "5.3.2" + } + ], "operations": [ { "name": "estimatedDocumentCount", @@ -627,22 +636,7 @@ { "commandStartedEvent": { "command": { - "aggregate": "test", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ], + "count": "test", "apiVersion": "1", "apiStrict": true, "apiDeprecationErrors": { diff --git a/test/spec/versioned-api/crud-api-version-1-strict.yml b/test/spec/versioned-api/crud-api-version-1-strict.yml index b5f3ac2d744..17c4bee0f9c 100644 --- a/test/spec/versioned-api/crud-api-version-1-strict.yml +++ b/test/spec/versioned-api/crud-api-version-1-strict.yml @@ -229,6 +229,11 @@ tests: <<: *expectedApiVersion - description: "estimatedDocumentCount appends declared API version" + # See: https://jira.mongodb.org/browse/SERVER-63850 + runOnRequirements: + - minServerVersion: "5.0.9" + maxServerVersion: "5.0.99" + - minServerVersion: "5.3.2" operations: - name: estimatedDocumentCount object: *collection @@ -238,10 +243,7 @@ tests: events: - commandStartedEvent: command: - aggregate: *collectionName - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} + count: *collectionName <<: *expectedApiVersion - description: "find and getMore append API version" diff --git a/test/spec/versioned-api/crud-api-version-1.json b/test/spec/versioned-api/crud-api-version-1.json index 1f135eea181..a387d0587e0 100644 --- a/test/spec/versioned-api/crud-api-version-1.json +++ b/test/spec/versioned-api/crud-api-version-1.json @@ -604,7 +604,16 @@ ] }, { - "description": "estimatedDocumentCount appends declared API version on 4.9.0 or greater", + "description": "estimatedDocumentCount appends declared API version", + "runOnRequirements": [ + { + "minServerVersion": "5.0.9", + "maxServerVersion": "5.0.99" + }, + { + "minServerVersion": "5.3.2" + } + ], "operations": [ { "name": "estimatedDocumentCount", @@ -619,22 +628,7 @@ { "commandStartedEvent": { "command": { - "aggregate": "test", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ], + "count": "test", "apiVersion": "1", "apiStrict": { "$$unsetOrMatches": false diff --git a/test/spec/versioned-api/crud-api-version-1.yml b/test/spec/versioned-api/crud-api-version-1.yml index d2fb5b91307..50135c14585 100644 --- a/test/spec/versioned-api/crud-api-version-1.yml +++ b/test/spec/versioned-api/crud-api-version-1.yml @@ -222,7 +222,12 @@ tests: key: x <<: *expectedApiVersion - - description: "estimatedDocumentCount appends declared API version on 4.9.0 or greater" + - description: "estimatedDocumentCount appends declared API version" + # See: https://jira.mongodb.org/browse/SERVER-63850 + runOnRequirements: + - minServerVersion: "5.0.9" + maxServerVersion: "5.0.99" + - minServerVersion: "5.3.2" operations: - name: estimatedDocumentCount object: *collection @@ -232,10 +237,7 @@ tests: events: - commandStartedEvent: command: - aggregate: *collectionName - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} + count: *collectionName <<: *expectedApiVersion - description: "find and getMore append API version" From 58f88db6acc80a304eb1c7663cef7ef361abba34 Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Mon, 16 May 2022 16:36:16 +0200 Subject: [PATCH 2/9] test(NODE-4079): adding tests not in spec commit --- .../estimatedDocumentCount.json | 19 +- .../estimatedDocumentCount.yml | 9 +- .../estimatedDocumentCount-comment.json | 170 ++++++ .../estimatedDocumentCount-comment.yml | 95 +++ .../estimatedDocumentCount-serverErrors.json | 546 ++++++++++++++++++ .../estimatedDocumentCount-serverErrors.yml | 148 +++++ .../legacy/estimatedDocumentCount.json | 166 ++++++ .../legacy/estimatedDocumentCount.yml | 62 ++ 8 files changed, 1192 insertions(+), 23 deletions(-) create mode 100644 test/spec/crud/unified/estimatedDocumentCount-comment.json create mode 100644 test/spec/crud/unified/estimatedDocumentCount-comment.yml create mode 100644 test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors.json create mode 100644 test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors.yml create mode 100644 test/spec/retryable-reads/legacy/estimatedDocumentCount.json create mode 100644 test/spec/retryable-reads/legacy/estimatedDocumentCount.yml diff --git a/test/spec/atlas-data-lake-testing/estimatedDocumentCount.json b/test/spec/atlas-data-lake-testing/estimatedDocumentCount.json index 87b385208d7..997a3ab3fcd 100644 --- a/test/spec/atlas-data-lake-testing/estimatedDocumentCount.json +++ b/test/spec/atlas-data-lake-testing/estimatedDocumentCount.json @@ -15,24 +15,9 @@ { "command_started_event": { "command": { - "aggregate": "driverdata", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] + "count": "driverdata" }, - "command_name": "aggregate", + "command_name": "count", "database_name": "test" } } diff --git a/test/spec/atlas-data-lake-testing/estimatedDocumentCount.yml b/test/spec/atlas-data-lake-testing/estimatedDocumentCount.yml index 43eee2d317d..64c6bbd04fb 100644 --- a/test/spec/atlas-data-lake-testing/estimatedDocumentCount.yml +++ b/test/spec/atlas-data-lake-testing/estimatedDocumentCount.yml @@ -13,9 +13,6 @@ tests: - command_started_event: command: - aggregate: *collection_name - pipeline: - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} - command_name: aggregate - database_name: *database_name + count: *collection_name + command_name: count + database_name: *database_name diff --git a/test/spec/crud/unified/estimatedDocumentCount-comment.json b/test/spec/crud/unified/estimatedDocumentCount-comment.json new file mode 100644 index 00000000000..6c0adacc8f1 --- /dev/null +++ b/test/spec/crud/unified/estimatedDocumentCount-comment.json @@ -0,0 +1,170 @@ +{ + "description": "estimatedDocumentCount-comment", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "edc-comment-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "edc-comment-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + } + ] + } + ], + "tests": [ + { + "description": "estimatedDocumentCount with document comment", + "runOnRequirements": [ + { + "minServerVersion": "4.4.14" + } + ], + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection0", + "arguments": { + "comment": { + "key": "value" + } + }, + "expectResult": 3 + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "count": "coll0", + "comment": { + "key": "value" + } + }, + "commandName": "count", + "databaseName": "edc-comment-tests" + } + } + ] + } + ] + }, + { + "description": "estimatedDocumentCount with string comment", + "runOnRequirements": [ + { + "minServerVersion": "4.4.0" + } + ], + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection0", + "arguments": { + "comment": "comment" + }, + "expectResult": 3 + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "count": "coll0", + "comment": "comment" + }, + "commandName": "count", + "databaseName": "edc-comment-tests" + } + } + ] + } + ] + }, + { + "description": "estimatedDocumentCount with document comment - pre 4.4.14, server error", + "runOnRequirements": [ + { + "minServerVersion": "3.6.0", + "maxServerVersion": "4.4.13", + "topologies": [ + "single", + "replicaset" + ] + } + ], + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection0", + "arguments": { + "comment": { + "key": "value" + } + }, + "expectError": { + "isClientError": false + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "count": "coll0", + "comment": { + "key": "value" + } + }, + "commandName": "count", + "databaseName": "edc-comment-tests" + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/crud/unified/estimatedDocumentCount-comment.yml b/test/spec/crud/unified/estimatedDocumentCount-comment.yml new file mode 100644 index 00000000000..b7853151048 --- /dev/null +++ b/test/spec/crud/unified/estimatedDocumentCount-comment.yml @@ -0,0 +1,95 @@ +description: "estimatedDocumentCount-comment" + +schemaVersion: "1.0" + +createEntities: + - client: + id: &client0 client0 + observeEvents: [ commandStartedEvent ] + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name edc-comment-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name coll0 + +initialData: + - collectionName: *collection0Name + databaseName: *database0Name + documents: + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + - { _id: 3, x: 33 } + +tests: + - description: "estimatedDocumentCount with document comment" + runOnRequirements: + # https://jira.mongodb.org/browse/SERVER-63315 + # Server supports count with comment of any type for comment starting from 4.4.14. + - minServerVersion: "4.4.14" + operations: + - name: estimatedDocumentCount + object: *collection0 + arguments: + comment: &documentComment { key: "value"} + expectResult: 3 + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + count: *collection0Name + comment: *documentComment + commandName: count + databaseName: *database0Name + + - description: "estimatedDocumentCount with string comment" + runOnRequirements: + - minServerVersion: "4.4.0" + operations: + - name: estimatedDocumentCount + object: *collection0 + arguments: + comment: &stringComment "comment" + expectResult: 3 + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + count: *collection0Name + comment: *stringComment + commandName: count + databaseName: *database0Name + + - description: "estimatedDocumentCount with document comment - pre 4.4.14, server error" + runOnRequirements: + - minServerVersion: "3.6.0" + maxServerVersion: "4.4.13" + # Server does not raise an error if topology is sharded. + # https://jira.mongodb.org/browse/SERVER-65954 + topologies: [ single, replicaset ] + operations: + - name: estimatedDocumentCount + object: *collection0 + arguments: + # Even though according to the docs count command does not support any + # comment for server version less than 4.4, no error is raised by such + # servers. Therefore, we have only one test with a document comment + # to test server errors. + # https://jira.mongodb.org/browse/SERVER-63315 + # Server supports count with comment of any type for comment starting from 4.4.14. + comment: *documentComment + expectError: + isClientError: false + expectEvents: + - client: *client0 + events: + - commandStartedEvent: + command: + count: *collection0Name + comment: *documentComment + commandName: count + databaseName: *database0Name diff --git a/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors.json b/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors.json new file mode 100644 index 00000000000..6bb128f5f37 --- /dev/null +++ b/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors.json @@ -0,0 +1,546 @@ +{ + "runOn": [ + { + "minServerVersion": "4.0", + "topology": [ + "single", + "replicaset" + ] + }, + { + "minServerVersion": "4.1.7", + "topology": [ + "sharded" + ] + } + ], + "database_name": "retryable-reads-tests", + "collection_name": "coll", + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "tests": [ + { + "description": "EstimatedDocumentCount succeeds after InterruptedAtShutdown", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "count" + ], + "errorCode": 11600 + } + }, + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection", + "result": 2 + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + }, + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + } + ] + }, + { + "description": "EstimatedDocumentCount succeeds after InterruptedDueToReplStateChange", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "count" + ], + "errorCode": 11602 + } + }, + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection", + "result": 2 + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + }, + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + } + ] + }, + { + "description": "EstimatedDocumentCount succeeds after NotWritablePrimary", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "count" + ], + "errorCode": 10107 + } + }, + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection", + "result": 2 + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + }, + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + } + ] + }, + { + "description": "EstimatedDocumentCount succeeds after NotPrimaryNoSecondaryOk", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "count" + ], + "errorCode": 13435 + } + }, + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection", + "result": 2 + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + }, + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + } + ] + }, + { + "description": "EstimatedDocumentCount succeeds after NotPrimaryOrSecondary", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "count" + ], + "errorCode": 13436 + } + }, + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection", + "result": 2 + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + }, + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + } + ] + }, + { + "description": "EstimatedDocumentCount succeeds after PrimarySteppedDown", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "count" + ], + "errorCode": 189 + } + }, + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection", + "result": 2 + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + }, + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + } + ] + }, + { + "description": "EstimatedDocumentCount succeeds after ShutdownInProgress", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "count" + ], + "errorCode": 91 + } + }, + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection", + "result": 2 + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + }, + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + } + ] + }, + { + "description": "EstimatedDocumentCount succeeds after HostNotFound", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "count" + ], + "errorCode": 7 + } + }, + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection", + "result": 2 + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + }, + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + } + ] + }, + { + "description": "EstimatedDocumentCount succeeds after HostUnreachable", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "count" + ], + "errorCode": 6 + } + }, + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection", + "result": 2 + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + }, + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + } + ] + }, + { + "description": "EstimatedDocumentCount succeeds after NetworkTimeout", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "count" + ], + "errorCode": 89 + } + }, + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection", + "result": 2 + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + }, + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + } + ] + }, + { + "description": "EstimatedDocumentCount succeeds after SocketException", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "count" + ], + "errorCode": 9001 + } + }, + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection", + "result": 2 + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + }, + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + } + ] + }, + { + "description": "EstimatedDocumentCount fails after two NotWritablePrimary errors", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 2 + }, + "data": { + "failCommands": [ + "count" + ], + "errorCode": 10107 + } + }, + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection", + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + }, + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + } + ] + }, + { + "description": "EstimatedDocumentCount fails after NotWritablePrimary when retryReads is false", + "clientOptions": { + "retryReads": false + }, + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "count" + ], + "errorCode": 10107 + } + }, + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection", + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + } + ] + } + ] +} diff --git a/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors.yml b/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors.yml new file mode 100644 index 00000000000..aefb89ca692 --- /dev/null +++ b/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors.yml @@ -0,0 +1,148 @@ +runOn: + - + minServerVersion: "4.0" + topology: ["single", "replicaset"] + - + minServerVersion: "4.1.7" + topology: ["sharded"] + +database_name: &database_name "retryable-reads-tests" +collection_name: &collection_name "coll" + +data: + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + +tests: + - + description: "EstimatedDocumentCount succeeds after InterruptedAtShutdown" + failPoint: &failCommand_failPoint + configureFailPoint: failCommand + mode: { times: 1 } + data: { failCommands: [count], errorCode: 11600 } + operations: + - &retryable_operation_succeeds + <<: &retryable_operation + name: estimatedDocumentCount + object: collection + result: 2 + expectations: + - &retryable_command_started_event + command_started_event: + command: + count: *collection_name + database_name: *database_name + - *retryable_command_started_event + - + description: "EstimatedDocumentCount succeeds after InterruptedDueToReplStateChange" + failPoint: + <<: *failCommand_failPoint + data: { failCommands: [count], errorCode: 11602 } + operations: [*retryable_operation_succeeds] + expectations: + - *retryable_command_started_event + - *retryable_command_started_event + - + description: "EstimatedDocumentCount succeeds after NotWritablePrimary" + failPoint: + <<: *failCommand_failPoint + data: { failCommands: [count], errorCode: 10107 } + operations: [*retryable_operation_succeeds] + expectations: + - *retryable_command_started_event + - *retryable_command_started_event + - + description: "EstimatedDocumentCount succeeds after NotPrimaryNoSecondaryOk" + failPoint: + <<: *failCommand_failPoint + data: { failCommands: [count], errorCode: 13435 } + operations: [*retryable_operation_succeeds] + expectations: + - *retryable_command_started_event + - *retryable_command_started_event + - + description: "EstimatedDocumentCount succeeds after NotPrimaryOrSecondary" + failPoint: + <<: *failCommand_failPoint + data: { failCommands: [count], errorCode: 13436 } + operations: [*retryable_operation_succeeds] + expectations: + - *retryable_command_started_event + - *retryable_command_started_event + - + description: "EstimatedDocumentCount succeeds after PrimarySteppedDown" + failPoint: + <<: *failCommand_failPoint + data: { failCommands: [count], errorCode: 189 } + operations: [*retryable_operation_succeeds] + expectations: + - *retryable_command_started_event + - *retryable_command_started_event + - + description: "EstimatedDocumentCount succeeds after ShutdownInProgress" + failPoint: + <<: *failCommand_failPoint + data: { failCommands: [count], errorCode: 91 } + operations: [*retryable_operation_succeeds] + expectations: + - *retryable_command_started_event + - *retryable_command_started_event + - + description: "EstimatedDocumentCount succeeds after HostNotFound" + failPoint: + <<: *failCommand_failPoint + data: { failCommands: [count], errorCode: 7 } + operations: [*retryable_operation_succeeds] + expectations: + - *retryable_command_started_event + - *retryable_command_started_event + - + description: "EstimatedDocumentCount succeeds after HostUnreachable" + failPoint: + <<: *failCommand_failPoint + data: { failCommands: [count], errorCode: 6 } + operations: [*retryable_operation_succeeds] + expectations: + - *retryable_command_started_event + - *retryable_command_started_event + - + description: "EstimatedDocumentCount succeeds after NetworkTimeout" + failPoint: + <<: *failCommand_failPoint + data: { failCommands: [count], errorCode: 89 } + operations: [*retryable_operation_succeeds] + expectations: + - *retryable_command_started_event + - *retryable_command_started_event + - + description: "EstimatedDocumentCount succeeds after SocketException" + failPoint: + <<: *failCommand_failPoint + data: { failCommands: [count], errorCode: 9001 } + operations: [*retryable_operation_succeeds] + expectations: + - *retryable_command_started_event + - *retryable_command_started_event + - + description: "EstimatedDocumentCount fails after two NotWritablePrimary errors" + failPoint: + <<: *failCommand_failPoint + mode: { times: 2 } + data: { failCommands: [count], errorCode: 10107 } + operations: + - &retryable_operation_fails + <<: *retryable_operation + error: true + expectations: + - *retryable_command_started_event + - *retryable_command_started_event + - + description: "EstimatedDocumentCount fails after NotWritablePrimary when retryReads is false" + clientOptions: + retryReads: false + failPoint: + <<: *failCommand_failPoint + data: { failCommands: [count], errorCode: 10107 } + operations: [*retryable_operation_fails] + expectations: + - *retryable_command_started_event diff --git a/test/spec/retryable-reads/legacy/estimatedDocumentCount.json b/test/spec/retryable-reads/legacy/estimatedDocumentCount.json new file mode 100644 index 00000000000..8dfa15a2cdb --- /dev/null +++ b/test/spec/retryable-reads/legacy/estimatedDocumentCount.json @@ -0,0 +1,166 @@ +{ + "runOn": [ + { + "minServerVersion": "4.0", + "topology": [ + "single", + "replicaset" + ] + }, + { + "minServerVersion": "4.1.7", + "topology": [ + "sharded" + ] + } + ], + "database_name": "retryable-reads-tests", + "collection_name": "coll", + "data": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + } + ], + "tests": [ + { + "description": "EstimatedDocumentCount succeeds on first attempt", + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection", + "result": 2 + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + } + ] + }, + { + "description": "EstimatedDocumentCount succeeds on second attempt", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "count" + ], + "closeConnection": true + } + }, + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection", + "result": 2 + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + }, + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + } + ] + }, + { + "description": "EstimatedDocumentCount fails on first attempt", + "clientOptions": { + "retryReads": false + }, + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 1 + }, + "data": { + "failCommands": [ + "count" + ], + "closeConnection": true + } + }, + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection", + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + } + ] + }, + { + "description": "EstimatedDocumentCount fails on second attempt", + "failPoint": { + "configureFailPoint": "failCommand", + "mode": { + "times": 2 + }, + "data": { + "failCommands": [ + "count" + ], + "closeConnection": true + } + }, + "operations": [ + { + "name": "estimatedDocumentCount", + "object": "collection", + "error": true + } + ], + "expectations": [ + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + }, + { + "command_started_event": { + "command": { + "count": "coll" + }, + "database_name": "retryable-reads-tests" + } + } + ] + } + ] +} diff --git a/test/spec/retryable-reads/legacy/estimatedDocumentCount.yml b/test/spec/retryable-reads/legacy/estimatedDocumentCount.yml new file mode 100644 index 00000000000..de03e483bb4 --- /dev/null +++ b/test/spec/retryable-reads/legacy/estimatedDocumentCount.yml @@ -0,0 +1,62 @@ +runOn: + - + minServerVersion: "4.0" + topology: ["single", "replicaset"] + - + minServerVersion: "4.1.7" + topology: ["sharded"] + +database_name: &database_name "retryable-reads-tests" +collection_name: &collection_name "coll" + +data: + - { _id: 1, x: 11 } + - { _id: 2, x: 22 } + +tests: + - + description: "EstimatedDocumentCount succeeds on first attempt" + operations: + - &retryable_operation_succeeds + <<: &retryable_operation + name: estimatedDocumentCount + object: collection + result: 2 + expectations: + - &retryable_command_started_event + command_started_event: + command: + count: *collection_name + database_name: *database_name + - + description: "EstimatedDocumentCount succeeds on second attempt" + failPoint: &failCommand_failPoint + configureFailPoint: failCommand + mode: { times: 1 } + data: + failCommands: [count] + closeConnection: true + operations: [*retryable_operation_succeeds] + expectations: + - *retryable_command_started_event + - *retryable_command_started_event + - + description: "EstimatedDocumentCount fails on first attempt" + clientOptions: + retryReads: false + failPoint: *failCommand_failPoint + operations: + - &retryable_operation_fails + <<: *retryable_operation + error: true + expectations: + - *retryable_command_started_event + - + description: "EstimatedDocumentCount fails on second attempt" + failPoint: + <<: *failCommand_failPoint + mode: { times: 2 } + operations: [*retryable_operation_fails] + expectations: + - *retryable_command_started_event + - *retryable_command_started_event From 3212b6a4415cd16e06c5046e3e8156312380d541 Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Mon, 16 May 2022 16:49:28 +0200 Subject: [PATCH 3/9] fix(NODE-4079): remove comment tests --- .../estimatedDocumentCount-comment.json | 170 ------------------ .../estimatedDocumentCount-comment.yml | 95 ---------- 2 files changed, 265 deletions(-) delete mode 100644 test/spec/crud/unified/estimatedDocumentCount-comment.json delete mode 100644 test/spec/crud/unified/estimatedDocumentCount-comment.yml diff --git a/test/spec/crud/unified/estimatedDocumentCount-comment.json b/test/spec/crud/unified/estimatedDocumentCount-comment.json deleted file mode 100644 index 6c0adacc8f1..00000000000 --- a/test/spec/crud/unified/estimatedDocumentCount-comment.json +++ /dev/null @@ -1,170 +0,0 @@ -{ - "description": "estimatedDocumentCount-comment", - "schemaVersion": "1.0", - "createEntities": [ - { - "client": { - "id": "client0", - "observeEvents": [ - "commandStartedEvent" - ] - } - }, - { - "database": { - "id": "database0", - "client": "client0", - "databaseName": "edc-comment-tests" - } - }, - { - "collection": { - "id": "collection0", - "database": "database0", - "collectionName": "coll0" - } - } - ], - "initialData": [ - { - "collectionName": "coll0", - "databaseName": "edc-comment-tests", - "documents": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - }, - { - "_id": 3, - "x": 33 - } - ] - } - ], - "tests": [ - { - "description": "estimatedDocumentCount with document comment", - "runOnRequirements": [ - { - "minServerVersion": "4.4.14" - } - ], - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection0", - "arguments": { - "comment": { - "key": "value" - } - }, - "expectResult": 3 - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "count": "coll0", - "comment": { - "key": "value" - } - }, - "commandName": "count", - "databaseName": "edc-comment-tests" - } - } - ] - } - ] - }, - { - "description": "estimatedDocumentCount with string comment", - "runOnRequirements": [ - { - "minServerVersion": "4.4.0" - } - ], - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection0", - "arguments": { - "comment": "comment" - }, - "expectResult": 3 - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "count": "coll0", - "comment": "comment" - }, - "commandName": "count", - "databaseName": "edc-comment-tests" - } - } - ] - } - ] - }, - { - "description": "estimatedDocumentCount with document comment - pre 4.4.14, server error", - "runOnRequirements": [ - { - "minServerVersion": "3.6.0", - "maxServerVersion": "4.4.13", - "topologies": [ - "single", - "replicaset" - ] - } - ], - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection0", - "arguments": { - "comment": { - "key": "value" - } - }, - "expectError": { - "isClientError": false - } - } - ], - "expectEvents": [ - { - "client": "client0", - "events": [ - { - "commandStartedEvent": { - "command": { - "count": "coll0", - "comment": { - "key": "value" - } - }, - "commandName": "count", - "databaseName": "edc-comment-tests" - } - } - ] - } - ] - } - ] -} diff --git a/test/spec/crud/unified/estimatedDocumentCount-comment.yml b/test/spec/crud/unified/estimatedDocumentCount-comment.yml deleted file mode 100644 index b7853151048..00000000000 --- a/test/spec/crud/unified/estimatedDocumentCount-comment.yml +++ /dev/null @@ -1,95 +0,0 @@ -description: "estimatedDocumentCount-comment" - -schemaVersion: "1.0" - -createEntities: - - client: - id: &client0 client0 - observeEvents: [ commandStartedEvent ] - - database: - id: &database0 database0 - client: *client0 - databaseName: &database0Name edc-comment-tests - - collection: - id: &collection0 collection0 - database: *database0 - collectionName: &collection0Name coll0 - -initialData: - - collectionName: *collection0Name - databaseName: *database0Name - documents: - - { _id: 1, x: 11 } - - { _id: 2, x: 22 } - - { _id: 3, x: 33 } - -tests: - - description: "estimatedDocumentCount with document comment" - runOnRequirements: - # https://jira.mongodb.org/browse/SERVER-63315 - # Server supports count with comment of any type for comment starting from 4.4.14. - - minServerVersion: "4.4.14" - operations: - - name: estimatedDocumentCount - object: *collection0 - arguments: - comment: &documentComment { key: "value"} - expectResult: 3 - expectEvents: - - client: *client0 - events: - - commandStartedEvent: - command: - count: *collection0Name - comment: *documentComment - commandName: count - databaseName: *database0Name - - - description: "estimatedDocumentCount with string comment" - runOnRequirements: - - minServerVersion: "4.4.0" - operations: - - name: estimatedDocumentCount - object: *collection0 - arguments: - comment: &stringComment "comment" - expectResult: 3 - expectEvents: - - client: *client0 - events: - - commandStartedEvent: - command: - count: *collection0Name - comment: *stringComment - commandName: count - databaseName: *database0Name - - - description: "estimatedDocumentCount with document comment - pre 4.4.14, server error" - runOnRequirements: - - minServerVersion: "3.6.0" - maxServerVersion: "4.4.13" - # Server does not raise an error if topology is sharded. - # https://jira.mongodb.org/browse/SERVER-65954 - topologies: [ single, replicaset ] - operations: - - name: estimatedDocumentCount - object: *collection0 - arguments: - # Even though according to the docs count command does not support any - # comment for server version less than 4.4, no error is raised by such - # servers. Therefore, we have only one test with a document comment - # to test server errors. - # https://jira.mongodb.org/browse/SERVER-63315 - # Server supports count with comment of any type for comment starting from 4.4.14. - comment: *documentComment - expectError: - isClientError: false - expectEvents: - - client: *client0 - events: - - commandStartedEvent: - command: - count: *collection0Name - comment: *documentComment - commandName: count - databaseName: *database0Name From 1231ee2a30cdaece678c464fb215d8e260dc9153 Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Mon, 16 May 2022 17:07:49 +0200 Subject: [PATCH 4/9] test(NODE-4079): remove 4.9 est doc count tests --- .../legacy/estimatedDocumentCount-4.9.json | 246 ----- .../legacy/estimatedDocumentCount-4.9.yml | 60 -- .../legacy/estimatedDocumentCount-pre4.9.json | 168 ---- .../legacy/estimatedDocumentCount-pre4.9.yml | 64 -- ...timatedDocumentCount-serverErrors-4.9.json | 911 ------------------ ...stimatedDocumentCount-serverErrors-4.9.yml | 146 --- ...atedDocumentCount-serverErrors-pre4.9.json | 548 ----------- ...matedDocumentCount-serverErrors-pre4.9.yml | 150 --- 8 files changed, 2293 deletions(-) delete mode 100644 test/spec/retryable-reads/legacy/estimatedDocumentCount-4.9.json delete mode 100644 test/spec/retryable-reads/legacy/estimatedDocumentCount-4.9.yml delete mode 100644 test/spec/retryable-reads/legacy/estimatedDocumentCount-pre4.9.json delete mode 100644 test/spec/retryable-reads/legacy/estimatedDocumentCount-pre4.9.yml delete mode 100644 test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-4.9.json delete mode 100644 test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-4.9.yml delete mode 100644 test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-pre4.9.json delete mode 100644 test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-pre4.9.yml diff --git a/test/spec/retryable-reads/legacy/estimatedDocumentCount-4.9.json b/test/spec/retryable-reads/legacy/estimatedDocumentCount-4.9.json deleted file mode 100644 index a4c46fc074a..00000000000 --- a/test/spec/retryable-reads/legacy/estimatedDocumentCount-4.9.json +++ /dev/null @@ -1,246 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.9.0" - } - ], - "database_name": "retryable-reads-tests", - "collection_name": "coll", - "data": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - } - ], - "tests": [ - { - "description": "EstimatedDocumentCount succeeds on first attempt", - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds on second attempt", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "closeConnection": true - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount fails on first attempt", - "clientOptions": { - "retryReads": false - }, - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "closeConnection": true - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "error": true - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount fails on second attempt", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 2 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "closeConnection": true - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "error": true - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - } - ] -} diff --git a/test/spec/retryable-reads/legacy/estimatedDocumentCount-4.9.yml b/test/spec/retryable-reads/legacy/estimatedDocumentCount-4.9.yml deleted file mode 100644 index 277ea010a4c..00000000000 --- a/test/spec/retryable-reads/legacy/estimatedDocumentCount-4.9.yml +++ /dev/null @@ -1,60 +0,0 @@ -runOn: - - minServerVersion: "4.9.0" - -database_name: &database_name "retryable-reads-tests" -collection_name: &collection_name "coll" - -data: - - { _id: 1, x: 11 } - - { _id: 2, x: 22 } - -tests: - - - description: "EstimatedDocumentCount succeeds on first attempt" - operations: - - &retryable_operation_succeeds - <<: &retryable_operation - name: estimatedDocumentCount - object: collection - result: 2 - expectations: - - &retryable_command_started_event - command_started_event: - command: - aggregate: *collection_name - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} - database_name: *database_name - - - description: "EstimatedDocumentCount succeeds on second attempt" - failPoint: &failCommand_failPoint - configureFailPoint: failCommand - mode: { times: 1 } - data: - failCommands: [aggregate] - closeConnection: true - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount fails on first attempt" - clientOptions: - retryReads: false - failPoint: *failCommand_failPoint - operations: - - &retryable_operation_fails - <<: *retryable_operation - error: true - expectations: - - *retryable_command_started_event - - - description: "EstimatedDocumentCount fails on second attempt" - failPoint: - <<: *failCommand_failPoint - mode: { times: 2 } - operations: [*retryable_operation_fails] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event diff --git a/test/spec/retryable-reads/legacy/estimatedDocumentCount-pre4.9.json b/test/spec/retryable-reads/legacy/estimatedDocumentCount-pre4.9.json deleted file mode 100644 index 44be966ae7f..00000000000 --- a/test/spec/retryable-reads/legacy/estimatedDocumentCount-pre4.9.json +++ /dev/null @@ -1,168 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.0", - "maxServerVersion": "4.8.99", - "topology": [ - "single", - "replicaset" - ] - }, - { - "minServerVersion": "4.1.7", - "maxServerVersion": "4.8.99", - "topology": [ - "sharded" - ] - } - ], - "database_name": "retryable-reads-tests", - "collection_name": "coll", - "data": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - } - ], - "tests": [ - { - "description": "EstimatedDocumentCount succeeds on first attempt", - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds on second attempt", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "count" - ], - "closeConnection": true - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount fails on first attempt", - "clientOptions": { - "retryReads": false - }, - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "count" - ], - "closeConnection": true - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "error": true - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount fails on second attempt", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 2 - }, - "data": { - "failCommands": [ - "count" - ], - "closeConnection": true - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "error": true - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - } - ] - } - ] -} diff --git a/test/spec/retryable-reads/legacy/estimatedDocumentCount-pre4.9.yml b/test/spec/retryable-reads/legacy/estimatedDocumentCount-pre4.9.yml deleted file mode 100644 index d03a171d912..00000000000 --- a/test/spec/retryable-reads/legacy/estimatedDocumentCount-pre4.9.yml +++ /dev/null @@ -1,64 +0,0 @@ -runOn: - - - minServerVersion: "4.0" - maxServerVersion: "4.8.99" - topology: ["single", "replicaset"] - - - minServerVersion: "4.1.7" - maxServerVersion: "4.8.99" - topology: ["sharded"] - -database_name: &database_name "retryable-reads-tests" -collection_name: &collection_name "coll" - -data: - - { _id: 1, x: 11 } - - { _id: 2, x: 22 } - -tests: - - - description: "EstimatedDocumentCount succeeds on first attempt" - operations: - - &retryable_operation_succeeds - <<: &retryable_operation - name: estimatedDocumentCount - object: collection - result: 2 - expectations: - - &retryable_command_started_event - command_started_event: - command: - count: *collection_name - database_name: *database_name - - - description: "EstimatedDocumentCount succeeds on second attempt" - failPoint: &failCommand_failPoint - configureFailPoint: failCommand - mode: { times: 1 } - data: - failCommands: [count] - closeConnection: true - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount fails on first attempt" - clientOptions: - retryReads: false - failPoint: *failCommand_failPoint - operations: - - &retryable_operation_fails - <<: *retryable_operation - error: true - expectations: - - *retryable_command_started_event - - - description: "EstimatedDocumentCount fails on second attempt" - failPoint: - <<: *failCommand_failPoint - mode: { times: 2 } - operations: [*retryable_operation_fails] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event diff --git a/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-4.9.json b/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-4.9.json deleted file mode 100644 index 756b02b3a85..00000000000 --- a/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-4.9.json +++ /dev/null @@ -1,911 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.9.0" - } - ], - "database_name": "retryable-reads-tests", - "collection_name": "coll", - "data": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - } - ], - "tests": [ - { - "description": "EstimatedDocumentCount succeeds after InterruptedAtShutdown", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 11600 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after InterruptedDueToReplStateChange", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 11602 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after NotWritablePrimary", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 10107 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after NotPrimaryNoSecondaryOk", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 13435 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after NotPrimaryOrSecondary", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 13436 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after PrimarySteppedDown", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 189 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after ShutdownInProgress", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 91 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after HostNotFound", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 7 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after HostUnreachable", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 6 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after NetworkTimeout", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 89 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after SocketException", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 9001 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount fails after two NotWritablePrimary errors", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 2 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 10107 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "error": true - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount fails after NotWritablePrimary when retryReads is false", - "clientOptions": { - "retryReads": false - }, - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "aggregate" - ], - "errorCode": 10107 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "error": true - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "aggregate": "coll", - "pipeline": [ - { - "$collStats": { - "count": {} - } - }, - { - "$group": { - "_id": 1, - "n": { - "$sum": "$count" - } - } - } - ] - }, - "database_name": "retryable-reads-tests" - } - } - ] - } - ] -} diff --git a/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-4.9.yml b/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-4.9.yml deleted file mode 100644 index 1a73d54312b..00000000000 --- a/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-4.9.yml +++ /dev/null @@ -1,146 +0,0 @@ -runOn: - - minServerVersion: "4.9.0" - -database_name: &database_name "retryable-reads-tests" -collection_name: &collection_name "coll" - -data: - - { _id: 1, x: 11 } - - { _id: 2, x: 22 } - -tests: - - - description: "EstimatedDocumentCount succeeds after InterruptedAtShutdown" - failPoint: &failCommand_failPoint - configureFailPoint: failCommand - mode: { times: 1 } - data: { failCommands: [aggregate], errorCode: 11600 } - operations: - - &retryable_operation_succeeds - <<: &retryable_operation - name: estimatedDocumentCount - object: collection - result: 2 - expectations: - - &retryable_command_started_event - command_started_event: - command: - aggregate: *collection_name - pipeline: &pipeline - - $collStats: { count: {} } - - $group: { _id: 1, n: { $sum: $count }} - database_name: *database_name - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after InterruptedDueToReplStateChange" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 11602 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after NotWritablePrimary" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 10107 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after NotPrimaryNoSecondaryOk" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 13435 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after NotPrimaryOrSecondary" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 13436 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after PrimarySteppedDown" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 189 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after ShutdownInProgress" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 91 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after HostNotFound" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 7 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after HostUnreachable" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 6 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after NetworkTimeout" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 89 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after SocketException" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 9001 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount fails after two NotWritablePrimary errors" - failPoint: - <<: *failCommand_failPoint - mode: { times: 2 } - data: { failCommands: [aggregate], errorCode: 10107 } - operations: - - &retryable_operation_fails - <<: *retryable_operation - error: true - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount fails after NotWritablePrimary when retryReads is false" - clientOptions: - retryReads: false - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [aggregate], errorCode: 10107 } - operations: [*retryable_operation_fails] - expectations: - - *retryable_command_started_event diff --git a/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-pre4.9.json b/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-pre4.9.json deleted file mode 100644 index 0b9a2615d1e..00000000000 --- a/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-pre4.9.json +++ /dev/null @@ -1,548 +0,0 @@ -{ - "runOn": [ - { - "minServerVersion": "4.0", - "maxServerVersion": "4.8.99", - "topology": [ - "single", - "replicaset" - ] - }, - { - "minServerVersion": "4.1.7", - "maxServerVersion": "4.8.99", - "topology": [ - "sharded" - ] - } - ], - "database_name": "retryable-reads-tests", - "collection_name": "coll", - "data": [ - { - "_id": 1, - "x": 11 - }, - { - "_id": 2, - "x": 22 - } - ], - "tests": [ - { - "description": "EstimatedDocumentCount succeeds after InterruptedAtShutdown", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "count" - ], - "errorCode": 11600 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after InterruptedDueToReplStateChange", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "count" - ], - "errorCode": 11602 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after NotWritablePrimary", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "count" - ], - "errorCode": 10107 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after NotPrimaryNoSecondaryOk", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "count" - ], - "errorCode": 13435 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after NotPrimaryOrSecondary", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "count" - ], - "errorCode": 13436 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after PrimarySteppedDown", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "count" - ], - "errorCode": 189 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after ShutdownInProgress", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "count" - ], - "errorCode": 91 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after HostNotFound", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "count" - ], - "errorCode": 7 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after HostUnreachable", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "count" - ], - "errorCode": 6 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after NetworkTimeout", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "count" - ], - "errorCode": 89 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount succeeds after SocketException", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "count" - ], - "errorCode": 9001 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "result": 2 - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount fails after two NotWritablePrimary errors", - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 2 - }, - "data": { - "failCommands": [ - "count" - ], - "errorCode": 10107 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "error": true - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - }, - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - } - ] - }, - { - "description": "EstimatedDocumentCount fails after NotWritablePrimary when retryReads is false", - "clientOptions": { - "retryReads": false - }, - "failPoint": { - "configureFailPoint": "failCommand", - "mode": { - "times": 1 - }, - "data": { - "failCommands": [ - "count" - ], - "errorCode": 10107 - } - }, - "operations": [ - { - "name": "estimatedDocumentCount", - "object": "collection", - "error": true - } - ], - "expectations": [ - { - "command_started_event": { - "command": { - "count": "coll" - }, - "database_name": "retryable-reads-tests" - } - } - ] - } - ] -} diff --git a/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-pre4.9.yml b/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-pre4.9.yml deleted file mode 100644 index 99c343b8895..00000000000 --- a/test/spec/retryable-reads/legacy/estimatedDocumentCount-serverErrors-pre4.9.yml +++ /dev/null @@ -1,150 +0,0 @@ -runOn: - - - minServerVersion: "4.0" - maxServerVersion: "4.8.99" - topology: ["single", "replicaset"] - - - minServerVersion: "4.1.7" - maxServerVersion: "4.8.99" - topology: ["sharded"] - -database_name: &database_name "retryable-reads-tests" -collection_name: &collection_name "coll" - -data: - - { _id: 1, x: 11 } - - { _id: 2, x: 22 } - -tests: - - - description: "EstimatedDocumentCount succeeds after InterruptedAtShutdown" - failPoint: &failCommand_failPoint - configureFailPoint: failCommand - mode: { times: 1 } - data: { failCommands: [count], errorCode: 11600 } - operations: - - &retryable_operation_succeeds - <<: &retryable_operation - name: estimatedDocumentCount - object: collection - result: 2 - expectations: - - &retryable_command_started_event - command_started_event: - command: - count: *collection_name - database_name: *database_name - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after InterruptedDueToReplStateChange" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [count], errorCode: 11602 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after NotWritablePrimary" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [count], errorCode: 10107 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after NotPrimaryNoSecondaryOk" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [count], errorCode: 13435 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after NotPrimaryOrSecondary" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [count], errorCode: 13436 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after PrimarySteppedDown" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [count], errorCode: 189 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after ShutdownInProgress" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [count], errorCode: 91 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after HostNotFound" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [count], errorCode: 7 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after HostUnreachable" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [count], errorCode: 6 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after NetworkTimeout" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [count], errorCode: 89 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount succeeds after SocketException" - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [count], errorCode: 9001 } - operations: [*retryable_operation_succeeds] - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount fails after two NotWritablePrimary errors" - failPoint: - <<: *failCommand_failPoint - mode: { times: 2 } - data: { failCommands: [count], errorCode: 10107 } - operations: - - &retryable_operation_fails - <<: *retryable_operation - error: true - expectations: - - *retryable_command_started_event - - *retryable_command_started_event - - - description: "EstimatedDocumentCount fails after NotWritablePrimary when retryReads is false" - clientOptions: - retryReads: false - failPoint: - <<: *failCommand_failPoint - data: { failCommands: [count], errorCode: 10107 } - operations: [*retryable_operation_fails] - expectations: - - *retryable_command_started_event From 3969ca77595931dc3d40c1a87836a4ada8134598 Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Mon, 16 May 2022 20:59:28 +0200 Subject: [PATCH 5/9] fix(NODE-4079): remove wire checks for est doc count --- src/collection.ts | 2 ++ src/operations/estimated_document_count.ts | 27 +--------------------- 2 files changed, 3 insertions(+), 26 deletions(-) diff --git a/src/collection.ts b/src/collection.ts index b749b8e76ba..3cba04443f1 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -1044,7 +1044,9 @@ export class Collection { /** * Gets an estimate of the count of documents in a collection using collection metadata. + * This will always run a count command on all server versions. * + * @see {@link https://www.mongodb.com/docs/manual/reference/command/count/#behavior|Count: Behavior} * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided */ diff --git a/src/operations/estimated_document_count.ts b/src/operations/estimated_document_count.ts index 45084a3c599..51675bcfef1 100644 --- a/src/operations/estimated_document_count.ts +++ b/src/operations/estimated_document_count.ts @@ -3,7 +3,7 @@ import type { Collection } from '../collection'; import type { MongoServerError } from '../error'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; -import { Callback, maxWireVersion } from '../utils'; +import type { Callback } from '../utils'; import { CommandOperation, CommandOperationOptions } from './command'; import { Aspect, defineAspects } from './operation'; @@ -33,10 +33,6 @@ export class EstimatedDocumentCountOperation extends CommandOperation { session: ClientSession | undefined, callback: Callback ): void { - if (maxWireVersion(server) < 12) { - return this.executeLegacy(server, session, callback); - } - const cmd: Document = { count: this.collectionName }; if (typeof this.options.maxTimeMS === 'number') { @@ -52,27 +48,6 @@ export class EstimatedDocumentCountOperation extends CommandOperation { callback(undefined, response?.n || 0); }); } - - executeLegacy( - server: Server, - session: ClientSession | undefined, - callback: Callback - ): void { - const cmd: Document = { count: this.collectionName }; - - if (typeof this.options.maxTimeMS === 'number') { - cmd.maxTimeMS = this.options.maxTimeMS; - } - - super.executeCommand(server, session, cmd, (err, response) => { - if (err) { - callback(err); - return; - } - - callback(undefined, response.n || 0); - }); - } } defineAspects(EstimatedDocumentCountOperation, [ From 874f1dfe705c6ab5dba2c64ae5308daf8873e40f Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Tue, 17 May 2022 15:18:09 +0200 Subject: [PATCH 6/9] fix(NODE-4079): update per comments --- src/collection.ts | 6 ++++++ src/operations/estimated_document_count.ts | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/collection.ts b/src/collection.ts index 3cba04443f1..5b532f32012 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -1046,6 +1046,12 @@ export class Collection { * Gets an estimate of the count of documents in a collection using collection metadata. * This will always run a count command on all server versions. * + * due to an oversight in versions 5.0.0-5.0.8 of MongoDB, the count command, + * which estimatedDocumentCount uses in its implementation, was not included in v1 of + * the Stable API, and so users of the Stable API with estimatedDocumentCount are + * recommended to upgrade their server version to 5.0.9+ or set apiStrict: false to avoid + * encountering errors. + * * @see {@link https://www.mongodb.com/docs/manual/reference/command/count/#behavior|Count: Behavior} * @param options - Optional settings for the command * @param callback - An optional callback, a Promise will be returned if none is provided diff --git a/src/operations/estimated_document_count.ts b/src/operations/estimated_document_count.ts index 51675bcfef1..d96ca44759d 100644 --- a/src/operations/estimated_document_count.ts +++ b/src/operations/estimated_document_count.ts @@ -1,6 +1,5 @@ import type { Document } from '../bson'; import type { Collection } from '../collection'; -import type { MongoServerError } from '../error'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; import type { Callback } from '../utils'; @@ -40,7 +39,7 @@ export class EstimatedDocumentCountOperation extends CommandOperation { } super.executeCommand(server, session, cmd, (err, response) => { - if (err && (err as MongoServerError).code !== 26) { + if (err) { callback(err); return; } From be2b234c16de0ba53f0d01374bf16aea90e3ecec Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Wed, 18 May 2022 15:46:53 +0200 Subject: [PATCH 7/9] test(NODE-4079): estimated document count takes no filter --- test/integration/collection-management/collection.test.js | 4 ++-- test/integration/read-write-concern/readconcern.test.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/collection-management/collection.test.js b/test/integration/collection-management/collection.test.js index db2fbe56308..4cb8f16dfc0 100644 --- a/test/integration/collection-management/collection.test.js +++ b/test/integration/collection-management/collection.test.js @@ -565,9 +565,9 @@ describe('Collection', function () { const close = e => client.close(() => done(e)); let thenFunction; if ( - test.title === 'should correctly perform estimatedDocumentCount on non-matching query' + test.title === 'should correctly perform estimatedDocumentCount' ) { - thenFunction = () => collection.estimatedDocumentCount({ a: 'b' }); + thenFunction = () => collection.estimatedDocumentCount(); } else if (test.title === 'should correctly perform countDocuments on non-matching query') { thenFunction = () => collection.countDocuments({ a: 'b' }); } diff --git a/test/integration/read-write-concern/readconcern.test.js b/test/integration/read-write-concern/readconcern.test.js index 765ba7d8dad..fa42a47b192 100644 --- a/test/integration/read-write-concern/readconcern.test.js +++ b/test/integration/read-write-concern/readconcern.test.js @@ -234,7 +234,7 @@ describe('ReadConcern', function () { done(); }); } else if (test.commandName === 'count') { - collection.estimatedDocumentCount({ a: 1 }, err => { + collection.estimatedDocumentCount(err => { expect(err).to.not.exist; validateTestResults(started, succeeded, test.commandName, test.readConcern.level); done(); From e147a6f67f640333ba4950d3f526f101371a3d16 Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Wed, 18 May 2022 16:44:10 +0200 Subject: [PATCH 8/9] fix(NODE-4079): fix lint error --- test/integration/collection-management/collection.test.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/integration/collection-management/collection.test.js b/test/integration/collection-management/collection.test.js index 4cb8f16dfc0..7417599473e 100644 --- a/test/integration/collection-management/collection.test.js +++ b/test/integration/collection-management/collection.test.js @@ -564,9 +564,7 @@ describe('Collection', function () { it(test.title, function (done) { const close = e => client.close(() => done(e)); let thenFunction; - if ( - test.title === 'should correctly perform estimatedDocumentCount' - ) { + if (test.title === 'should correctly perform estimatedDocumentCount') { thenFunction = () => collection.estimatedDocumentCount(); } else if (test.title === 'should correctly perform countDocuments on non-matching query') { thenFunction = () => collection.countDocuments({ a: 'b' }); From 5a8a2d924ca727724ad890272235aa7243b01ec9 Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Wed, 18 May 2022 17:12:37 +0200 Subject: [PATCH 9/9] test(NODE-4079): rewrite count tests --- .../collection-management/collection.test.js | 110 +++++++++--------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/test/integration/collection-management/collection.test.js b/test/integration/collection-management/collection.test.js index 7417599473e..53c1278023e 100644 --- a/test/integration/collection-management/collection.test.js +++ b/test/integration/collection-management/collection.test.js @@ -535,79 +535,81 @@ describe('Collection', function () { }); }); - describe('(countDocuments)', function () { + describe('#estimatedDocumentCount', function () { let client; let db; let collection; - beforeEach(function () { + + beforeEach(async function () { client = configuration.newClient({ w: 1 }); - return client.connect().then(client => { - db = client.db(configuration.db); - collection = db.collection('test_coll'); - }); - }); - afterEach(function () { - return client.close(); + await client.connect(); + db = client.db(configuration.db); + collection = db.collection('test_coll'); + await collection.insertOne({ a: 'c' }); }); - const nonMatchQueryTests = [ - { - title: 'should correctly perform estimatedDocumentCount on non-matching query' - }, - { - title: 'should correctly perform countDocuments on non-matching query' - } - ]; + afterEach(async function () { + await collection.drop(); + await client.close(); + }); - nonMatchQueryTests.forEach(test => { - it(test.title, function (done) { - const close = e => client.close(() => done(e)); - let thenFunction; - if (test.title === 'should correctly perform estimatedDocumentCount') { - thenFunction = () => collection.estimatedDocumentCount(); - } else if (test.title === 'should correctly perform countDocuments on non-matching query') { - thenFunction = () => collection.countDocuments({ a: 'b' }); - } - Promise.resolve() - .then(thenFunction) - .then(count => expect(count).to.equal(0)) - .then(() => close()) - .catch(e => close(e)); - }); + it('returns the total documents in the collection', async function () { + const result = await collection.estimatedDocumentCount(); + expect(result).to.equal(1); }); + }); - it('countDocuments should return Promise that resolves when no callback passed', function (done) { - const docsPromise = collection.countDocuments(); - const close = e => client.close(() => done(e)); + describe('#countDocuments', function () { + let client; + let db; + let collection; - expect(docsPromise).to.exist.and.to.be.an.instanceof(Promise); + beforeEach(async function () { + client = configuration.newClient({ w: 1 }); + await client.connect(); + db = client.db(configuration.db); + collection = db.collection('test_coll'); + await collection.insertOne({ a: 'c' }); + }); - docsPromise - .then(result => expect(result).to.equal(0)) - .then(() => close()) - .catch(e => close(e)); + afterEach(async function () { + await collection.drop(); + await client.close(); }); - it('countDocuments should not return a promise if callback given', function (done) { - const close = e => client.close(() => done(e)); + context('when passing a non-matching query', function () { + it('returns 0', async function () { + const result = await collection.countDocuments({ a: 'b' }); + expect(result).to.equal(0); + }); + }); - const notPromise = collection.countDocuments({ a: 1 }, () => { - expect(notPromise).to.be.undefined; - close(); + context('when no callback passed', function () { + it('returns a promise', function () { + const docsPromise = collection.countDocuments(); + expect(docsPromise).to.exist.and.to.be.an.instanceof(Promise); + return docsPromise.then(result => expect(result).to.equal(1)); }); }); - it('countDocuments should correctly call the given callback', function (done) { - const docs = [{ a: 1 }, { a: 2 }]; - const close = e => client.close(() => done(e)); + context('when a callback is passed', function () { + it('does not return a promise', function (done) { + const notPromise = collection.countDocuments({ a: 1 }, () => { + expect(notPromise).to.be.undefined; + done(); + }); + }); - collection.insertMany(docs).then(() => - collection.countDocuments({ a: 1 }, (err, data) => { - expect(data).to.equal(1); - close(err); - }) - ); + it('calls the callback', function (done) { + const docs = [{ a: 1 }, { a: 2 }]; + collection.insertMany(docs).then(() => + collection.countDocuments({ a: 1 }, (err, data) => { + expect(data).to.equal(1); + done(err); + }) + ); + }); }); });