Skip to content

Commit 6826e0c

Browse files
authored
RUST-768 Pass versioned API parameters to getMore and transaction-continuing commands. (#397)
1 parent 1af685e commit 6826e0c

18 files changed

+157
-296
lines changed

src/cmap/conn/command.rs

-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ impl Command {
4646
}
4747

4848
pub(crate) fn set_server_api(&mut self, server_api: &ServerApi) {
49-
if matches!(self.name.as_str(), "getMore") {
50-
return;
51-
}
52-
5349
self.body
5450
.insert("apiVersion", format!("{}", server_api.version));
5551

src/test/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mod spec;
1111
mod util;
1212

1313
pub(crate) use self::{
14-
spec::{run_single_test, run_spec_test, RunOn, Serverless, Topology},
14+
spec::{run_single_test, run_spec_test, run_spec_test_with_path, RunOn, Serverless, Topology},
1515
util::{
1616
assert_matches,
1717
CmapEvent,

src/test/spec/json/versioned-api/README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ To run this test, proceed as follows:
3333
- If the environment variable is set, all clients created in tests MUST declare
3434
the ``ServerApiVersion`` specified.
3535

36-
No other topologies must be tested until ``mongo-orchestration`` can handle
37-
servers with ``requireApiVersion`` enabled.
36+
Only standalone servers must be tested. The tests should run for each server
37+
version >= 5.0, including ``latest``.

src/test/spec/json/versioned-api/crud-api-version-1-strict.json

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"description": "CRUD Api Version 1 (strict)",
3-
"schemaVersion": "1.1",
3+
"schemaVersion": "1.4",
44
"runOnRequirements": [
55
{
66
"minServerVersion": "4.9"
@@ -141,6 +141,11 @@
141141
},
142142
{
143143
"description": "aggregate on database appends declared API version",
144+
"runOnRequirements": [
145+
{
146+
"serverless": "forbid"
147+
}
148+
],
144149
"operations": [
145150
{
146151
"name": "aggregate",
@@ -651,7 +656,7 @@
651656
]
652657
},
653658
{
654-
"description": "find command with declared API version appends to the command, but getMore does not",
659+
"description": "find and getMore append API version",
655660
"operations": [
656661
{
657662
"name": "find",
@@ -712,14 +717,10 @@
712717
"long"
713718
]
714719
},
715-
"apiVersion": {
716-
"$$exists": false
717-
},
718-
"apiStrict": {
719-
"$$exists": false
720-
},
720+
"apiVersion": "1",
721+
"apiStrict": true,
721722
"apiDeprecationErrors": {
722-
"$$exists": false
723+
"$$unsetOrMatches": false
723724
}
724725
}
725726
}

src/test/spec/json/versioned-api/crud-api-version-1-strict.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
description: "CRUD Api Version 1 (strict)"
22

3-
schemaVersion: "1.1"
3+
schemaVersion: "1.4"
44

55
runOnRequirements:
66
- minServerVersion: "4.9"
@@ -62,6 +62,10 @@ tests:
6262
<<: *expectedApiVersion
6363

6464
- description: "aggregate on database appends declared API version"
65+
runOnRequirements:
66+
# serverless does not support either of the current database-level aggregation stages ($listLocalSessions and
67+
# $currentOp)
68+
- serverless: "forbid"
6569
operations:
6670
- name: aggregate
6771
object: *adminDatabase
@@ -240,7 +244,7 @@ tests:
240244
- $group: { _id: 1, n: { $sum: $count }}
241245
<<: *expectedApiVersion
242246

243-
- description: "find command with declared API version appends to the command, but getMore does not"
247+
- description: "find and getMore append API version"
244248
operations:
245249
- name: find
246250
object: *collection
@@ -264,9 +268,7 @@ tests:
264268
- commandStartedEvent:
265269
command:
266270
getMore: { $$type: [ int, long ] }
267-
apiVersion: { $$exists: false }
268-
apiStrict: { $$exists: false }
269-
apiDeprecationErrors: { $$exists: false }
271+
<<: *expectedApiVersion
270272

271273
- description: "findOneAndDelete appends declared API version"
272274
operations:

src/test/spec/json/versioned-api/crud-api-version-1.json

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"description": "CRUD Api Version 1",
3-
"schemaVersion": "1.1",
3+
"schemaVersion": "1.4",
44
"runOnRequirements": [
55
{
66
"minServerVersion": "4.9"
@@ -141,6 +141,11 @@
141141
},
142142
{
143143
"description": "aggregate on database appends declared API version",
144+
"runOnRequirements": [
145+
{
146+
"serverless": "forbid"
147+
}
148+
],
144149
"operations": [
145150
{
146151
"name": "aggregate",
@@ -643,7 +648,7 @@
643648
]
644649
},
645650
{
646-
"description": "find command with declared API version appends to the command, but getMore does not",
651+
"description": "find and getMore append API version",
647652
"operations": [
648653
{
649654
"name": "find",
@@ -704,15 +709,11 @@
704709
"long"
705710
]
706711
},
707-
"apiVersion": {
708-
"$$exists": false
709-
},
712+
"apiVersion": "1",
710713
"apiStrict": {
711-
"$$exists": false
714+
"$$unsetOrMatches": false
712715
},
713-
"apiDeprecationErrors": {
714-
"$$exists": false
715-
}
716+
"apiDeprecationErrors": true
716717
}
717718
}
718719
}

src/test/spec/json/versioned-api/crud-api-version-1.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
description: "CRUD Api Version 1"
22

3-
schemaVersion: "1.1"
3+
schemaVersion: "1.4"
44

55
runOnRequirements:
66
- minServerVersion: "4.9"
@@ -64,6 +64,10 @@ tests:
6464
<<: *expectedApiVersion
6565

6666
- description: "aggregate on database appends declared API version"
67+
runOnRequirements:
68+
# serverless does not support either of the current database-level aggregation stages ($listLocalSessions and
69+
# $currentOp)
70+
- serverless: forbid
6771
operations:
6872
- name: aggregate
6973
object: *adminDatabase
@@ -234,7 +238,7 @@ tests:
234238
- $group: { _id: 1, n: { $sum: $count }}
235239
<<: *expectedApiVersion
236240

237-
- description: "find command with declared API version appends to the command, but getMore does not"
241+
- description: "find and getMore append API version"
238242
operations:
239243
- name: find
240244
object: *collection
@@ -258,9 +262,7 @@ tests:
258262
- commandStartedEvent:
259263
command:
260264
getMore: { $$type: [ int, long ] }
261-
apiVersion: { $$exists: false }
262-
apiStrict: { $$exists: false }
263-
apiDeprecationErrors: { $$exists: false }
265+
<<: *expectedApiVersion
264266

265267
- description: "findOneAndDelete appends declared API version"
266268
operations:

src/test/spec/json/versioned-api/runcommand-helper-no-api-version-declared.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"description": "RunCommand helper: No API version declared",
3-
"schemaVersion": "1.1",
3+
"schemaVersion": "1.4",
44
"runOnRequirements": [
55
{
66
"minServerVersion": "4.9",
@@ -29,6 +29,11 @@
2929
"tests": [
3030
{
3131
"description": "runCommand does not inspect or change the command document",
32+
"runOnRequirements": [
33+
{
34+
"serverless": "forbid"
35+
}
36+
],
3237
"operations": [
3338
{
3439
"name": "runCommand",
@@ -72,6 +77,11 @@
7277
},
7378
{
7479
"description": "runCommand does not prevent sending invalid API version declarations",
80+
"runOnRequirements": [
81+
{
82+
"serverless": "forbid"
83+
}
84+
],
7585
"operations": [
7686
{
7787
"name": "runCommand",

src/test/spec/json/versioned-api/runcommand-helper-no-api-version-declared.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
description: "RunCommand helper: No API version declared"
22

3-
schemaVersion: "1.1"
3+
schemaVersion: "1.4"
44

55
runOnRequirements:
66
- minServerVersion: "4.9"
@@ -19,6 +19,10 @@ createEntities:
1919

2020
tests:
2121
- description: "runCommand does not inspect or change the command document"
22+
runOnRequirements:
23+
# serverless does not currently reject invalid API versions on
24+
# certain commands (CLOUDP-87926)
25+
- serverless: "forbid"
2226
operations:
2327
- name: runCommand
2428
object: *database
@@ -43,6 +47,10 @@ tests:
4347
databaseName: *databaseName
4448

4549
- description: "runCommand does not prevent sending invalid API version declarations"
50+
runOnRequirements:
51+
# serverless does not currently reject invalid API versions on
52+
# certain commands (CLOUDP-87926)
53+
- serverless: "forbid"
4654
operations:
4755
- name: runCommand
4856
object: *database

src/test/spec/json/versioned-api/test-commands-strict-mode.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"description": "Test commands: strict mode",
3-
"schemaVersion": "1.1",
3+
"schemaVersion": "1.4",
44
"runOnRequirements": [
55
{
66
"minServerVersion": "4.9",
77
"serverParameters": {
88
"enableTestCommands": true
9-
}
9+
},
10+
"serverless": "forbid"
1011
}
1112
],
1213
"createEntities": [

src/test/spec/json/versioned-api/test-commands-strict-mode.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
description: "Test commands: strict mode"
22

3-
schemaVersion: "1.1"
3+
schemaVersion: "1.4"
44

55
runOnRequirements:
66
- minServerVersion: "4.9"
77
serverParameters:
88
enableTestCommands: true
9+
# serverless gives a different error for unrecognized testVersion2 command
10+
serverless: "forbid"
911

1012
createEntities:
1113
- client:

0 commit comments

Comments
 (0)