From e75631322e6eae0e81d70da09f3a4c5108864910 Mon Sep 17 00:00:00 2001 From: Abraham Egnor Date: Wed, 14 Jul 2021 13:51:14 -0400 Subject: [PATCH 1/5] enable version on getMore, and enable versioned api tests for 5.0 --- src/cmap/conn/command.rs | 4 ---- src/test/spec/versioned_api.rs | 4 ---- 2 files changed, 8 deletions(-) diff --git a/src/cmap/conn/command.rs b/src/cmap/conn/command.rs index 31b300e3f..efc9adc22 100644 --- a/src/cmap/conn/command.rs +++ b/src/cmap/conn/command.rs @@ -46,10 +46,6 @@ impl Command { } pub(crate) fn set_server_api(&mut self, server_api: &ServerApi) { - if matches!(self.name.as_str(), "getMore") { - return; - } - self.body .insert("apiVersion", format!("{}", server_api.version)); diff --git a/src/test/spec/versioned_api.rs b/src/test/spec/versioned_api.rs index 16ca90553..7787e8056 100644 --- a/src/test/spec/versioned_api.rs +++ b/src/test/spec/versioned_api.rs @@ -12,10 +12,6 @@ use super::run_unified_format_test; #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn run() { let _guard: RwLockWriteGuard<_> = LOCK.run_exclusively().await; - // TODO RUST-768 Unskip these tests on 5.0 - if TestClient::new().await.server_version_gte(5, 0) { - return; - } run_spec_test(&["versioned-api"], run_unified_format_test).await; } From d6500ac93716b26add41a475ad6193d73f5cbd72 Mon Sep 17 00:00:00 2001 From: Abraham Egnor Date: Mon, 19 Jul 2021 11:22:23 -0400 Subject: [PATCH 2/5] update spec tests --- src/test/spec/json/versioned-api/README.rst | 4 +- .../crud-api-version-1-strict.json | 19 +- .../crud-api-version-1-strict.yml | 12 +- .../versioned-api/crud-api-version-1.json | 19 +- .../json/versioned-api/crud-api-version-1.yml | 12 +- ...ommand-helper-no-api-version-declared.json | 12 +- ...command-helper-no-api-version-declared.yml | 10 +- .../test-commands-strict-mode.json | 5 +- .../test-commands-strict-mode.yml | 4 +- .../versioned-api/transaction-handling.json | 207 ++---------------- .../versioned-api/transaction-handling.yml | 70 +----- src/test/spec/unified_runner/mod.rs | 2 +- src/test/spec/unified_runner/test_file.rs | 2 + src/test/spec/versioned_api.rs | 2 +- src/test/util/mod.rs | 1 + 15 files changed, 94 insertions(+), 287 deletions(-) diff --git a/src/test/spec/json/versioned-api/README.rst b/src/test/spec/json/versioned-api/README.rst index a0b0599f6..ccc91240f 100644 --- a/src/test/spec/json/versioned-api/README.rst +++ b/src/test/spec/json/versioned-api/README.rst @@ -33,5 +33,5 @@ To run this test, proceed as follows: - If the environment variable is set, all clients created in tests MUST declare the ``ServerApiVersion`` specified. -No other topologies must be tested until ``mongo-orchestration`` can handle -servers with ``requireApiVersion`` enabled. +Only standalone servers must be tested. The tests should run for each server +version >= 5.0, including ``latest``. diff --git a/src/test/spec/json/versioned-api/crud-api-version-1-strict.json b/src/test/spec/json/versioned-api/crud-api-version-1-strict.json index 2705b505a..29a0ec4e3 100644 --- a/src/test/spec/json/versioned-api/crud-api-version-1-strict.json +++ b/src/test/spec/json/versioned-api/crud-api-version-1-strict.json @@ -1,6 +1,6 @@ { "description": "CRUD Api Version 1 (strict)", - "schemaVersion": "1.1", + "schemaVersion": "1.4", "runOnRequirements": [ { "minServerVersion": "4.9" @@ -141,6 +141,11 @@ }, { "description": "aggregate on database appends declared API version", + "runOnRequirements": [ + { + "serverless": "forbid" + } + ], "operations": [ { "name": "aggregate", @@ -651,7 +656,7 @@ ] }, { - "description": "find command with declared API version appends to the command, but getMore does not", + "description": "find and getMore append API version", "operations": [ { "name": "find", @@ -712,14 +717,10 @@ "long" ] }, - "apiVersion": { - "$$exists": false - }, - "apiStrict": { - "$$exists": false - }, + "apiVersion": "1", + "apiStrict": true, "apiDeprecationErrors": { - "$$exists": false + "$$unsetOrMatches": false } } } diff --git a/src/test/spec/json/versioned-api/crud-api-version-1-strict.yml b/src/test/spec/json/versioned-api/crud-api-version-1-strict.yml index 83b72f756..b5f3ac2d7 100644 --- a/src/test/spec/json/versioned-api/crud-api-version-1-strict.yml +++ b/src/test/spec/json/versioned-api/crud-api-version-1-strict.yml @@ -1,6 +1,6 @@ description: "CRUD Api Version 1 (strict)" -schemaVersion: "1.1" +schemaVersion: "1.4" runOnRequirements: - minServerVersion: "4.9" @@ -62,6 +62,10 @@ tests: <<: *expectedApiVersion - description: "aggregate on database appends declared API version" + runOnRequirements: + # serverless does not support either of the current database-level aggregation stages ($listLocalSessions and + # $currentOp) + - serverless: "forbid" operations: - name: aggregate object: *adminDatabase @@ -240,7 +244,7 @@ tests: - $group: { _id: 1, n: { $sum: $count }} <<: *expectedApiVersion - - description: "find command with declared API version appends to the command, but getMore does not" + - description: "find and getMore append API version" operations: - name: find object: *collection @@ -264,9 +268,7 @@ tests: - commandStartedEvent: command: getMore: { $$type: [ int, long ] } - apiVersion: { $$exists: false } - apiStrict: { $$exists: false } - apiDeprecationErrors: { $$exists: false } + <<: *expectedApiVersion - description: "findOneAndDelete appends declared API version" operations: diff --git a/src/test/spec/json/versioned-api/crud-api-version-1.json b/src/test/spec/json/versioned-api/crud-api-version-1.json index 917185837..1f135eea1 100644 --- a/src/test/spec/json/versioned-api/crud-api-version-1.json +++ b/src/test/spec/json/versioned-api/crud-api-version-1.json @@ -1,6 +1,6 @@ { "description": "CRUD Api Version 1", - "schemaVersion": "1.1", + "schemaVersion": "1.4", "runOnRequirements": [ { "minServerVersion": "4.9" @@ -141,6 +141,11 @@ }, { "description": "aggregate on database appends declared API version", + "runOnRequirements": [ + { + "serverless": "forbid" + } + ], "operations": [ { "name": "aggregate", @@ -643,7 +648,7 @@ ] }, { - "description": "find command with declared API version appends to the command, but getMore does not", + "description": "find and getMore append API version", "operations": [ { "name": "find", @@ -704,15 +709,11 @@ "long" ] }, - "apiVersion": { - "$$exists": false - }, + "apiVersion": "1", "apiStrict": { - "$$exists": false + "$$unsetOrMatches": false }, - "apiDeprecationErrors": { - "$$exists": false - } + "apiDeprecationErrors": true } } } diff --git a/src/test/spec/json/versioned-api/crud-api-version-1.yml b/src/test/spec/json/versioned-api/crud-api-version-1.yml index 3c72e079d..d2fb5b913 100644 --- a/src/test/spec/json/versioned-api/crud-api-version-1.yml +++ b/src/test/spec/json/versioned-api/crud-api-version-1.yml @@ -1,6 +1,6 @@ description: "CRUD Api Version 1" -schemaVersion: "1.1" +schemaVersion: "1.4" runOnRequirements: - minServerVersion: "4.9" @@ -64,6 +64,10 @@ tests: <<: *expectedApiVersion - description: "aggregate on database appends declared API version" + runOnRequirements: + # serverless does not support either of the current database-level aggregation stages ($listLocalSessions and + # $currentOp) + - serverless: forbid operations: - name: aggregate object: *adminDatabase @@ -234,7 +238,7 @@ tests: - $group: { _id: 1, n: { $sum: $count }} <<: *expectedApiVersion - - description: "find command with declared API version appends to the command, but getMore does not" + - description: "find and getMore append API version" operations: - name: find object: *collection @@ -258,9 +262,7 @@ tests: - commandStartedEvent: command: getMore: { $$type: [ int, long ] } - apiVersion: { $$exists: false } - apiStrict: { $$exists: false } - apiDeprecationErrors: { $$exists: false } + <<: *expectedApiVersion - description: "findOneAndDelete appends declared API version" operations: diff --git a/src/test/spec/json/versioned-api/runcommand-helper-no-api-version-declared.json b/src/test/spec/json/versioned-api/runcommand-helper-no-api-version-declared.json index e901887e4..17e0126d1 100644 --- a/src/test/spec/json/versioned-api/runcommand-helper-no-api-version-declared.json +++ b/src/test/spec/json/versioned-api/runcommand-helper-no-api-version-declared.json @@ -1,6 +1,6 @@ { "description": "RunCommand helper: No API version declared", - "schemaVersion": "1.1", + "schemaVersion": "1.4", "runOnRequirements": [ { "minServerVersion": "4.9", @@ -29,6 +29,11 @@ "tests": [ { "description": "runCommand does not inspect or change the command document", + "runOnRequirements": [ + { + "serverless": "forbid" + } + ], "operations": [ { "name": "runCommand", @@ -72,6 +77,11 @@ }, { "description": "runCommand does not prevent sending invalid API version declarations", + "runOnRequirements": [ + { + "serverless": "forbid" + } + ], "operations": [ { "name": "runCommand", diff --git a/src/test/spec/json/versioned-api/runcommand-helper-no-api-version-declared.yml b/src/test/spec/json/versioned-api/runcommand-helper-no-api-version-declared.yml index c735a32a3..c17481ab1 100644 --- a/src/test/spec/json/versioned-api/runcommand-helper-no-api-version-declared.yml +++ b/src/test/spec/json/versioned-api/runcommand-helper-no-api-version-declared.yml @@ -1,6 +1,6 @@ description: "RunCommand helper: No API version declared" -schemaVersion: "1.1" +schemaVersion: "1.4" runOnRequirements: - minServerVersion: "4.9" @@ -19,6 +19,10 @@ createEntities: tests: - description: "runCommand does not inspect or change the command document" + runOnRequirements: + # serverless does not currently reject invalid API versions on + # certain commands (CLOUDP-87926) + - serverless: "forbid" operations: - name: runCommand object: *database @@ -43,6 +47,10 @@ tests: databaseName: *databaseName - description: "runCommand does not prevent sending invalid API version declarations" + runOnRequirements: + # serverless does not currently reject invalid API versions on + # certain commands (CLOUDP-87926) + - serverless: "forbid" operations: - name: runCommand object: *database diff --git a/src/test/spec/json/versioned-api/test-commands-strict-mode.json b/src/test/spec/json/versioned-api/test-commands-strict-mode.json index 1705ba7bf..9c4ebea78 100644 --- a/src/test/spec/json/versioned-api/test-commands-strict-mode.json +++ b/src/test/spec/json/versioned-api/test-commands-strict-mode.json @@ -1,12 +1,13 @@ { "description": "Test commands: strict mode", - "schemaVersion": "1.1", + "schemaVersion": "1.4", "runOnRequirements": [ { "minServerVersion": "4.9", "serverParameters": { "enableTestCommands": true - } + }, + "serverless": "forbid" } ], "createEntities": [ diff --git a/src/test/spec/json/versioned-api/test-commands-strict-mode.yml b/src/test/spec/json/versioned-api/test-commands-strict-mode.yml index d7c2c1564..f53b6e6a2 100644 --- a/src/test/spec/json/versioned-api/test-commands-strict-mode.yml +++ b/src/test/spec/json/versioned-api/test-commands-strict-mode.yml @@ -1,11 +1,13 @@ description: "Test commands: strict mode" -schemaVersion: "1.1" +schemaVersion: "1.4" runOnRequirements: - minServerVersion: "4.9" serverParameters: enableTestCommands: true + # serverless gives a different error for unrecognized testVersion2 command + serverless: "forbid" createEntities: - client: diff --git a/src/test/spec/json/versioned-api/transaction-handling.json b/src/test/spec/json/versioned-api/transaction-handling.json index a740405d3..c00c5240a 100644 --- a/src/test/spec/json/versioned-api/transaction-handling.json +++ b/src/test/spec/json/versioned-api/transaction-handling.json @@ -1,12 +1,13 @@ { "description": "Transaction handling", - "schemaVersion": "1.1", + "schemaVersion": "1.3", "runOnRequirements": [ { "minServerVersion": "4.9", "topologies": [ "replicaset", - "sharded-replicaset" + "sharded-replicaset", + "load-balanced" ] } ], @@ -53,17 +54,6 @@ "apiDeprecationErrors": { "$$unsetOrMatches": false } - }, - { - "apiVersion": { - "$$exists": false - }, - "apiStrict": { - "$$exists": false - }, - "apiDeprecationErrors": { - "$$exists": false - } } ] }, @@ -97,12 +87,13 @@ ], "tests": [ { - "description": "Only the first command in a transaction declares an API version", + "description": "All commands in a transaction declare an API version", "runOnRequirements": [ { "topologies": [ "replicaset", - "sharded-replicaset" + "sharded-replicaset", + "load-balanced" ] } ], @@ -193,119 +184,6 @@ "lsid": { "$$sessionLsid": "session" }, - "apiVersion": { - "$$exists": false - }, - "apiStrict": { - "$$exists": false - }, - "apiDeprecationErrors": { - "$$exists": false - } - } - } - }, - { - "commandStartedEvent": { - "command": { - "commitTransaction": 1, - "lsid": { - "$$sessionLsid": "session" - }, - "apiVersion": { - "$$exists": false - }, - "apiStrict": { - "$$exists": false - }, - "apiDeprecationErrors": { - "$$exists": false - } - } - } - } - ] - } - ] - }, - { - "description": "Committing a transaction twice does not append server API options", - "runOnRequirements": [ - { - "topologies": [ - "replicaset", - "sharded-replicaset" - ] - } - ], - "operations": [ - { - "name": "startTransaction", - "object": "session" - }, - { - "name": "insertOne", - "object": "collection", - "arguments": { - "session": "session", - "document": { - "_id": 6, - "x": 66 - } - }, - "expectResult": { - "$$unsetOrMatches": { - "insertedId": { - "$$unsetOrMatches": 6 - } - } - } - }, - { - "name": "insertOne", - "object": "collection", - "arguments": { - "session": "session", - "document": { - "_id": 7, - "x": 77 - } - }, - "expectResult": { - "$$unsetOrMatches": { - "insertedId": { - "$$unsetOrMatches": 7 - } - } - } - }, - { - "name": "commitTransaction", - "object": "session" - }, - { - "name": "commitTransaction", - "object": "session" - } - ], - "expectEvents": [ - { - "client": "client", - "events": [ - { - "commandStartedEvent": { - "command": { - "insert": "test", - "documents": [ - { - "_id": 6, - "x": 66 - } - ], - "lsid": { - "$$sessionLsid": "session" - }, - "startTransaction": true, "apiVersion": "1", "apiStrict": { "$$unsetOrMatches": false @@ -316,31 +194,6 @@ } } }, - { - "commandStartedEvent": { - "command": { - "insert": "test", - "documents": [ - { - "_id": 7, - "x": 77 - } - ], - "lsid": { - "$$sessionLsid": "session" - }, - "apiVersion": { - "$$exists": false - }, - "apiStrict": { - "$$exists": false - }, - "apiDeprecationErrors": { - "$$exists": false - } - } - } - }, { "commandStartedEvent": { "command": { @@ -348,33 +201,12 @@ "lsid": { "$$sessionLsid": "session" }, - "apiVersion": { - "$$exists": false - }, - "apiStrict": { - "$$exists": false - }, - "apiDeprecationErrors": { - "$$exists": false - } - } - } - }, - { - "commandStartedEvent": { - "command": { - "commitTransaction": 1, - "lsid": { - "$$sessionLsid": "session" - }, - "apiVersion": { - "$$exists": false - }, + "apiVersion": "1", "apiStrict": { - "$$exists": false + "$$unsetOrMatches": false }, "apiDeprecationErrors": { - "$$exists": false + "$$unsetOrMatches": false } } } @@ -384,12 +216,13 @@ ] }, { - "description": "abortTransaction does not include an API version", + "description": "abortTransaction includes an API version", "runOnRequirements": [ { "topologies": [ "replicaset", - "sharded-replicaset" + "sharded-replicaset", + "load-balanced" ] } ], @@ -480,14 +313,12 @@ "lsid": { "$$sessionLsid": "session" }, - "apiVersion": { - "$$exists": false - }, + "apiVersion": "1", "apiStrict": { - "$$exists": false + "$$unsetOrMatches": false }, "apiDeprecationErrors": { - "$$exists": false + "$$unsetOrMatches": false } } } @@ -499,14 +330,12 @@ "lsid": { "$$sessionLsid": "session" }, - "apiVersion": { - "$$exists": false - }, + "apiVersion": "1", "apiStrict": { - "$$exists": false + "$$unsetOrMatches": false }, "apiDeprecationErrors": { - "$$exists": false + "$$unsetOrMatches": false } } } diff --git a/src/test/spec/json/versioned-api/transaction-handling.yml b/src/test/spec/json/versioned-api/transaction-handling.yml index bd4fe8505..011f37dd6 100644 --- a/src/test/spec/json/versioned-api/transaction-handling.yml +++ b/src/test/spec/json/versioned-api/transaction-handling.yml @@ -1,10 +1,10 @@ description: "Transaction handling" -schemaVersion: "1.1" +schemaVersion: "1.3" runOnRequirements: - minServerVersion: "4.9" - topologies: [ replicaset, sharded-replicaset ] + topologies: [ replicaset, sharded-replicaset, load-balanced ] createEntities: - client: @@ -31,10 +31,6 @@ _yamlAnchors: apiVersion: "1" apiStrict: { $$unsetOrMatches: false } apiDeprecationErrors: { $$unsetOrMatches: false } - - &noApiVersion - apiVersion: { $$exists: false } - apiStrict: { $$exists: false } - apiDeprecationErrors: { $$exists: false } initialData: @@ -48,9 +44,9 @@ initialData: - { _id: 5, x: 55 } tests: - - description: "Only the first command in a transaction declares an API version" + - description: "All commands in a transaction declare an API version" runOnRequirements: - - topologies: [ replicaset, sharded-replicaset ] + - topologies: [ replicaset, sharded-replicaset, load-balanced ] operations: - name: startTransaction object: *session @@ -83,63 +79,15 @@ tests: insert: *collectionName documents: [ { _id: 7, x: 77 } ] lsid: { $$sessionLsid: *session } - <<: *noApiVersion - - commandStartedEvent: - command: - commitTransaction: 1 - lsid: { $$sessionLsid: *session } - <<: *noApiVersion - - description: "Committing a transaction twice does not append server API options" - runOnRequirements: - - topologies: [ replicaset, sharded-replicaset ] - operations: - - name: startTransaction - object: *session - - name: insertOne - object: *collection - arguments: - session: *session - document: { _id: 6, x: 66 } - expectResult: { $$unsetOrMatches: { insertedId: { $$unsetOrMatches: 6 } } } - - name: insertOne - object: *collection - arguments: - session: *session - document: { _id: 7, x: 77 } - expectResult: { $$unsetOrMatches: { insertedId: { $$unsetOrMatches: 7 } } } - - name: commitTransaction - object: *session - - name: commitTransaction - object: *session - expectEvents: - - client: *client - events: - - commandStartedEvent: - command: - insert: *collectionName - documents: [ { _id: 6, x: 66 } ] - lsid: { $$sessionLsid: *session } - startTransaction: true <<: *expectedApiVersion - - commandStartedEvent: - command: - insert: *collectionName - documents: [ { _id: 7, x: 77 } ] - lsid: { $$sessionLsid: *session } - <<: *noApiVersion - commandStartedEvent: command: commitTransaction: 1 lsid: { $$sessionLsid: *session } - <<: *noApiVersion - - commandStartedEvent: - command: - commitTransaction: 1 - lsid: { $$sessionLsid: *session } - <<: *noApiVersion - - description: "abortTransaction does not include an API version" + <<: *expectedApiVersion + - description: "abortTransaction includes an API version" runOnRequirements: - - topologies: [ replicaset, sharded-replicaset ] + - topologies: [ replicaset, sharded-replicaset, load-balanced ] operations: - name: startTransaction object: *session @@ -172,9 +120,9 @@ tests: insert: *collectionName documents: [ { _id: 7, x: 77 } ] lsid: { $$sessionLsid: *session } - <<: *noApiVersion + <<: *expectedApiVersion - commandStartedEvent: command: abortTransaction: 1 lsid: { $$sessionLsid: *session } - <<: *noApiVersion + <<: *expectedApiVersion diff --git a/src/test/spec/unified_runner/mod.rs b/src/test/spec/unified_runner/mod.rs index 02cf2c692..adc770b59 100644 --- a/src/test/spec/unified_runner/mod.rs +++ b/src/test/spec/unified_runner/mod.rs @@ -34,7 +34,7 @@ pub use self::{ test_runner::{EntityMap, TestRunner}, }; -static SPEC_VERSIONS: &[Version] = &[Version::new(1, 0, 0), Version::new(1, 1, 0)]; +static SPEC_VERSIONS: &[Version] = &[Version::new(1, 0, 0), Version::new(1, 1, 0), Version::new(1, 4, 0)]; const SKIPPED_OPERATIONS: &[&str] = &[ "assertIndexExists", diff --git a/src/test/spec/unified_runner/test_file.rs b/src/test/spec/unified_runner/test_file.rs index 844292677..04ecdbd2f 100644 --- a/src/test/spec/unified_runner/test_file.rs +++ b/src/test/spec/unified_runner/test_file.rs @@ -72,6 +72,8 @@ pub enum Topology { Sharded, #[serde(rename = "sharded-replicaset")] ShardedReplicaSet, + #[serde(rename = "load-balanced")] + LoadBalanced, } impl RunOnRequirement { diff --git a/src/test/spec/versioned_api.rs b/src/test/spec/versioned_api.rs index 7787e8056..103a3e0ee 100644 --- a/src/test/spec/versioned_api.rs +++ b/src/test/spec/versioned_api.rs @@ -3,7 +3,7 @@ use tokio::sync::{RwLockReadGuard, RwLockWriteGuard}; use crate::{ bson::doc, options::{ServerApi, ServerApiVersion}, - test::{run_spec_test, EventClient, TestClient, CLIENT_OPTIONS, LOCK}, + test::{run_spec_test, EventClient, CLIENT_OPTIONS, LOCK}, }; use super::run_unified_format_test; diff --git a/src/test/util/mod.rs b/src/test/util/mod.rs index 4011c059b..edc64afe7 100644 --- a/src/test/util/mod.rs +++ b/src/test/util/mod.rs @@ -303,6 +303,7 @@ impl TestClient { } pub async fn topology(&self) -> Topology { + // TODO RUST-653 Detect and report a `LoadBalanced` topology. if self.is_sharded() { let shard_info = self .database("config") From 92682da4fc8549ca0b5b6ddb2369226213aaa087 Mon Sep 17 00:00:00 2001 From: Abraham Egnor Date: Mon, 19 Jul 2021 11:23:15 -0400 Subject: [PATCH 3/5] rustfmt --- src/test/spec/unified_runner/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/spec/unified_runner/mod.rs b/src/test/spec/unified_runner/mod.rs index adc770b59..10e229fb7 100644 --- a/src/test/spec/unified_runner/mod.rs +++ b/src/test/spec/unified_runner/mod.rs @@ -34,7 +34,11 @@ pub use self::{ test_runner::{EntityMap, TestRunner}, }; -static SPEC_VERSIONS: &[Version] = &[Version::new(1, 0, 0), Version::new(1, 1, 0), Version::new(1, 4, 0)]; +static SPEC_VERSIONS: &[Version] = &[ + Version::new(1, 0, 0), + Version::new(1, 1, 0), + Version::new(1, 4, 0), +]; const SKIPPED_OPERATIONS: &[&str] = &[ "assertIndexExists", From be1cdd864f151442f3ed4b5e1901094d8f844f5d Mon Sep 17 00:00:00 2001 From: Abraham Egnor Date: Mon, 19 Jul 2021 12:13:26 -0400 Subject: [PATCH 4/5] skip tests on sharded clusters --- src/test/spec/versioned_api.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/spec/versioned_api.rs b/src/test/spec/versioned_api.rs index 103a3e0ee..d3852f3a4 100644 --- a/src/test/spec/versioned_api.rs +++ b/src/test/spec/versioned_api.rs @@ -3,7 +3,7 @@ use tokio::sync::{RwLockReadGuard, RwLockWriteGuard}; use crate::{ bson::doc, options::{ServerApi, ServerApiVersion}, - test::{run_spec_test, EventClient, CLIENT_OPTIONS, LOCK}, + test::{run_spec_test, EventClient, TestClient, CLIENT_OPTIONS, LOCK}, }; use super::run_unified_format_test; @@ -12,6 +12,10 @@ use super::run_unified_format_test; #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn run() { let _guard: RwLockWriteGuard<_> = LOCK.run_exclusively().await; + // TODO RUST-734 Unskip these tests on sharded deployments. + if TestClient::new().await.is_sharded() { + return; + } run_spec_test(&["versioned-api"], run_unified_format_test).await; } From c5d190e37341593f5f44b7d3d633b9959a333738 Mon Sep 17 00:00:00 2001 From: Abraham Egnor Date: Mon, 19 Jul 2021 16:15:39 -0400 Subject: [PATCH 5/5] only exclude transaction handling test on sharded clusters --- src/test/mod.rs | 2 +- src/test/spec/mod.rs | 21 ++++++++++++++++- src/test/spec/versioned_api.rs | 41 +++++++++++++++++++++++++++++++--- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/test/mod.rs b/src/test/mod.rs index 4957a831c..58601af15 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -11,7 +11,7 @@ mod spec; mod util; pub(crate) use self::{ - spec::{run_single_test, run_spec_test, RunOn, Serverless, Topology}, + spec::{run_single_test, run_spec_test, run_spec_test_with_path, RunOn, Serverless, Topology}, util::{ assert_matches, CmapEvent, diff --git a/src/test/spec/mod.rs b/src/test/spec/mod.rs index 3cf256d34..f04e4c8a1 100644 --- a/src/test/spec/mod.rs +++ b/src/test/spec/mod.rs @@ -43,6 +43,15 @@ where F: Fn(T) -> G, G: Future, T: DeserializeOwned, +{ + run_spec_test_with_path(spec, |_, t| run_test_file(t)).await +} + +pub(crate) async fn run_spec_test_with_path(spec: &[&str], run_test_file: F) +where + F: Fn(PathBuf, T) -> G, + G: Future, + T: DeserializeOwned, { let base_path: PathBuf = [env!("CARGO_MANIFEST_DIR"), "src", "test", "spec", "json"] .iter() @@ -62,7 +71,7 @@ where } let test_file_full_path = base_path.join(&test_file_path); - run_single_test(test_file_full_path, &run_test_file).await; + run_single_test_with_path(test_file_full_path, &run_test_file).await; } } @@ -71,6 +80,15 @@ where F: Fn(T) -> G, G: Future, T: DeserializeOwned, +{ + run_single_test_with_path(path, &|_, t| run_test_file(t)).await +} + +pub(crate) async fn run_single_test_with_path(path: PathBuf, run_test_file: &F) +where + F: Fn(PathBuf, T) -> G, + G: Future, + T: DeserializeOwned, { let json: Value = serde_json::from_reader(File::open(path.as_path()).unwrap()).unwrap(); @@ -78,6 +96,7 @@ where println!("Running tests from {}", path.display().to_string()); run_test_file( + path.clone(), bson::from_bson( Bson::try_from(json).unwrap_or_else(|_| panic!("{}", path.display().to_string())), ) diff --git a/src/test/spec/versioned_api.rs b/src/test/spec/versioned_api.rs index d3852f3a4..c38ad8b6f 100644 --- a/src/test/spec/versioned_api.rs +++ b/src/test/spec/versioned_api.rs @@ -1,9 +1,19 @@ +use std::path::PathBuf; + use tokio::sync::{RwLockReadGuard, RwLockWriteGuard}; use crate::{ bson::doc, options::{ServerApi, ServerApiVersion}, - test::{run_spec_test, EventClient, TestClient, CLIENT_OPTIONS, LOCK}, + test::{ + run_single_test, + run_spec_test_with_path, + spec::unified_runner::TestFile, + EventClient, + TestClient, + CLIENT_OPTIONS, + LOCK, + }, }; use super::run_unified_format_test; @@ -12,11 +22,36 @@ use super::run_unified_format_test; #[cfg_attr(feature = "async-std-runtime", async_std::test)] async fn run() { let _guard: RwLockWriteGuard<_> = LOCK.run_exclusively().await; - // TODO RUST-734 Unskip these tests on sharded deployments. + run_spec_test_with_path(&["versioned-api"], run_non_transaction_handling_test).await; +} + +#[cfg_attr(feature = "tokio-runtime", tokio::test)] +#[cfg_attr(feature = "async-std-runtime", async_std::test)] +async fn run_transaction_handling_spec_test() { + let _guard: RwLockWriteGuard<_> = LOCK.run_exclusively().await; if TestClient::new().await.is_sharded() { + // TODO RUST-734 Unskip these tests on sharded deployments. + return; + } + let path: PathBuf = [ + env!("CARGO_MANIFEST_DIR"), + "src", + "test", + "spec", + "json", + "versioned-api", + "transaction-handling.json", + ] + .iter() + .collect(); + run_single_test(path, &run_unified_format_test).await; +} + +async fn run_non_transaction_handling_test(path: PathBuf, file: TestFile) { + if path.ends_with("transaction-handling.json") { return; } - run_spec_test(&["versioned-api"], run_unified_format_test).await; + run_unified_format_test(file).await } // TODO RUST-817 Remove this test in favor of transaction-handling.json versioned API spec test when