Skip to content

Commit ece1840

Browse files
committed
CSHARP-2626: Use runOn syntax to specify transaction test requirements.
1 parent 42d6f3c commit ece1840

File tree

74 files changed

+829
-195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+829
-195
lines changed

tests/MongoDB.Driver.Tests/Specifications/Runner/MongoClientJsonDrivenSessionsTestRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public abstract class MongoClientJsonDrivenSessionsTestRunner : MongoClientJsonD
2525
{
2626
private const string SessionIdKeySuffix = "__ClientSessionId";
2727

28-
protected override string[] ExpectedTestColumns => new[] { "description", "clientOptions", "failPoint", "sessionOptions", "operations", "expectations", "outcome", "async" };
28+
protected override string[] ExpectedTestColumns => new[] { "description", "clientOptions", "useMultipleMongoses", "failPoint", "sessionOptions", "operations", "expectations", "outcome", "async" };
2929

3030
// protected methods`
3131
protected override void TestInitialize()

tests/MongoDB.Driver.Tests/Specifications/Runner/MongoClientJsonDrivenTestRunnerBase.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public abstract class MongoClientJsonDrivenTestRunnerBase
5757
"getnonce"
5858
};
5959

60-
private readonly string[] _expectedSharedColumns = { "_path", "database_name", "collection_name", "data", "tests", "minServerVersion" };
60+
private readonly string[] _expectedSharedColumns = { "_path", "runOn", "database_name", "collection_name", "data", "tests" };
6161

6262
private string DatabaseName { get; set; }
6363
private string CollectionName { get; set; }
@@ -147,12 +147,11 @@ protected virtual void AssertOutcome(BsonDocument test)
147147

148148
protected virtual void CheckServerRequirements(BsonDocument document)
149149
{
150-
if (document.Contains("minServerVersion"))
150+
if (document.TryGetValue("runOn", out var runOn))
151151
{
152-
var minServerVersion = document["minServerVersion"].AsString;
153-
RequireServer.Check().VersionGreaterThanOrEqualTo(minServerVersion);
152+
RequireServer.Check().RunOn(runOn.AsBsonArray);
154153
}
155-
}
154+
}
156155

157156
protected virtual void ConfigureClientSettings(MongoClientSettings settings, BsonDocument test)
158157
{
@@ -269,14 +268,17 @@ protected void CreateCollection()
269268

270269
protected DisposableMongoClient CreateDisposableClient(BsonDocument test, EventCapturer eventCapturer)
271270
{
272-
return DriverTestConfiguration.CreateDisposableClient(settings =>
273-
{
274-
ConfigureClientSettings(settings, test);
275-
if (eventCapturer != null)
271+
var useMultipleShardRouters = test.GetValue("useMultipleMongoses", false).AsBoolean;
272+
return DriverTestConfiguration.CreateDisposableClient(
273+
settings =>
276274
{
277-
settings.ClusterConfigurator = c => c.Subscribe(eventCapturer);
278-
}
279-
});
275+
ConfigureClientSettings(settings, test);
276+
if (eventCapturer != null)
277+
{
278+
settings.ClusterConfigurator = c => c.Subscribe(eventCapturer);
279+
}
280+
},
281+
useMultipleShardRouters);
280282
}
281283

282284
protected void DropCollection()
@@ -354,6 +356,9 @@ private ReadPreference ReadPreferenceFromBsonValue(BsonValue value)
354356

355357
private void SetupAndRunTest(BsonDocument shared, BsonDocument test)
356358
{
359+
JsonDrivenHelper.EnsureAllFieldsAreValid(shared, ExpectedSharedColumns);
360+
JsonDrivenHelper.EnsureAllFieldsAreValid(test, ExpectedTestColumns);
361+
357362
if (test.Contains(SkipReasonKey))
358363
{
359364
throw new SkipException(test[SkipReasonKey].AsString);
@@ -362,8 +367,6 @@ private void SetupAndRunTest(BsonDocument shared, BsonDocument test)
362367
Ensure.IsNotNullOrEmpty(DatabaseNameKey, nameof(DatabaseNameKey));
363368
Ensure.IsNotNullOrEmpty(CollectionNameKey, nameof(CollectionNameKey));
364369

365-
JsonDrivenHelper.EnsureAllFieldsAreValid(shared, ExpectedSharedColumns);
366-
JsonDrivenHelper.EnsureAllFieldsAreValid(test, ExpectedTestColumns);
367370
CustomDataValidation(shared, test);
368371

369372
DatabaseName = shared[DatabaseNameKey].AsString;

tests/MongoDB.Driver.Tests/Specifications/transactions-convenient-api/TransactionsConvenientApiTestRunner.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,6 @@ public void Run(JsonDrivenTestCase testCase)
3434
SetupAndRunTest(testCase);
3535
}
3636

37-
protected override void CheckServerRequirements(BsonDocument document)
38-
{
39-
base.CheckServerRequirements(document);
40-
var clusterType = CoreTestConfiguration.Cluster.Description.Type;
41-
RequireServer.Check().ClusterTypes(ClusterType.ReplicaSet, ClusterType.Sharded);
42-
if (clusterType == ClusterType.ReplicaSet)
43-
{
44-
RequireServer.Check().Supports(Feature.Transactions);
45-
}
46-
else if (clusterType == ClusterType.Sharded)
47-
{
48-
RequireServer.Check().Supports(Feature.ShardedTransactions);
49-
}
50-
}
51-
5237
protected override void RunTest(BsonDocument shared, BsonDocument test, EventCapturer eventCapturer)
5338
{
5439
using (var client = CreateDisposableClient(test, eventCapturer))

tests/MongoDB.Driver.Tests/Specifications/transactions-convenient-api/tests/README.rst

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,33 @@ Test Format
2828

2929
Each YAML file has the following keys:
3030

31+
- ``runOn`` (optional): An array of server version and/or topology requirements
32+
for which the tests can be run. If the test environment satisfies one or more
33+
of these requirements, the tests may be executed; otherwise, this file should
34+
be skipped. If this field is omitted, the tests can be assumed to have no
35+
particular requirements and should be executed. Each element will have some or
36+
all of the following fields:
37+
38+
- ``minServerVersion`` (optional): The minimum server version (inclusive)
39+
required to successfully run the tests. If this field is omitted, it should
40+
be assumed that there is no lower bound on the required server version.
41+
42+
- ``maxServerVersion`` (optional): The maximum server version (inclusive)
43+
against which the tests can be run successfully. If this field is omitted,
44+
it should be assumed that there is no upper bound on the required server
45+
version.
46+
47+
- ``topology`` (optional): An array of server topologies against which the
48+
tests can be run successfully. Valid topologies are "single", "replicaset",
49+
and "sharded". If this field is omitted, the default is all topologies (i.e.
50+
``["single", "replicaset", "sharded"]``).
51+
3152
- ``database_name`` and ``collection_name``: The database and collection to use
3253
for testing.
3354

3455
- ``data``: The data that should exist in the collection under test before each
3556
test run.
3657

37-
- ``minServerVersion`` (optional): The minimum server version (inclusive)
38-
required to successfully run the test. If this field is not present, it should
39-
be assumed that there is no lower bound on the required server version.
40-
4158
- ``tests``: An array of tests that are to be run independently of each other.
4259
Each test will have some or all of the following fields:
4360

@@ -47,7 +64,13 @@ Each YAML file has the following keys:
4764
string value will specify a reason.
4865

4966
- ``failPoint`` (optional): The ``configureFailPoint`` command document to run
50-
to configure a fail point on the primary server.
67+
to configure a fail point on the primary server. This option and
68+
``useMultipleMongoses: true`` are mutually exclusive.
69+
70+
- ``useMultipleMongoses`` (optional): If ``true``, the MongoClient for this
71+
test should be initialized with multiple mongos seed addresses. If ``false``
72+
or omitted, only a single mongos address should be specified. This field has
73+
no effect for non-sharded topologies.
5174

5275
- ``clientOptions`` (optional): Names and values of options to pass to
5376
``MongoClient()``.
@@ -186,3 +209,12 @@ should be checked:
186209
by internally modifying the timeout value used by ``withTransaction`` with some
187210
private API or using a mock timer.
188211

212+
Changelog
213+
=========
214+
215+
:2019-03-01: Add top-level ``runOn`` field to denote server version and/or
216+
topology requirements requirements for the test file. Removes the
217+
``minServerVersion`` top-level field, which is now expressed within
218+
``runOn`` elements.
219+
220+
Add top-level ``useMultipleMongoses`` field.

tests/MongoDB.Driver.Tests/Specifications/transactions-convenient-api/tests/callback-aborts.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.0",
5+
"topology": [
6+
"replicaset"
7+
]
8+
},
9+
{
10+
"minServerVersion": "4.1.8",
11+
"topology": [
12+
"sharded"
13+
]
14+
}
15+
],
216
"database_name": "withTransaction-tests",
317
"collection_name": "test",
418
"data": [],
519
"tests": [
620
{
721
"description": "withTransaction succeeds if callback aborts",
22+
"useMultipleMongoses": true,
823
"operations": [
924
{
1025
"name": "withTransaction",
@@ -84,6 +99,7 @@
8499
},
85100
{
86101
"description": "withTransaction succeeds if callback aborts with no ops",
102+
"useMultipleMongoses": true,
87103
"operations": [
88104
{
89105
"name": "withTransaction",
@@ -109,6 +125,7 @@
109125
},
110126
{
111127
"description": "withTransaction still succeeds if callback aborts and runs extra op",
128+
"useMultipleMongoses": true,
112129
"operations": [
113130
{
114131
"name": "withTransaction",

tests/MongoDB.Driver.Tests/Specifications/transactions-convenient-api/tests/callback-aborts.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
runOn:
2+
-
3+
minServerVersion: "4.0"
4+
topology: ["replicaset"]
5+
-
6+
minServerVersion: "4.1.8"
7+
topology: ["sharded"]
8+
19
database_name: &database_name "withTransaction-tests"
210
collection_name: &collection_name "test"
311

@@ -7,6 +15,7 @@ tests:
715
-
816
# Session state will be ABORTED when callback returns to withTransaction
917
description: withTransaction succeeds if callback aborts
18+
useMultipleMongoses: true
1019
operations:
1120
-
1221
name: withTransaction
@@ -61,6 +70,7 @@ tests:
6170
-
6271
# Session state will be ABORTED when callback returns to withTransaction
6372
description: withTransaction succeeds if callback aborts with no ops
73+
useMultipleMongoses: true
6474
operations:
6575
-
6676
name: withTransaction
@@ -78,6 +88,7 @@ tests:
7888
-
7989
# Session state will be NO_TXN when callback returns to withTransaction
8090
description: withTransaction still succeeds if callback aborts and runs extra op
91+
useMultipleMongoses: true
8192
operations:
8293
-
8394
name: withTransaction

tests/MongoDB.Driver.Tests/Specifications/transactions-convenient-api/tests/callback-commits.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.0",
5+
"topology": [
6+
"replicaset"
7+
]
8+
},
9+
{
10+
"minServerVersion": "4.1.8",
11+
"topology": [
12+
"sharded"
13+
]
14+
}
15+
],
216
"database_name": "withTransaction-tests",
317
"collection_name": "test",
418
"data": [],
519
"tests": [
620
{
721
"description": "withTransaction succeeds if callback commits",
22+
"useMultipleMongoses": true,
823
"operations": [
924
{
1025
"name": "withTransaction",
@@ -127,6 +142,7 @@
127142
},
128143
{
129144
"description": "withTransaction still succeeds if callback commits and runs extra op",
145+
"useMultipleMongoses": true,
130146
"operations": [
131147
{
132148
"name": "withTransaction",

tests/MongoDB.Driver.Tests/Specifications/transactions-convenient-api/tests/callback-commits.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
runOn:
2+
-
3+
minServerVersion: "4.0"
4+
topology: ["replicaset"]
5+
-
6+
minServerVersion: "4.1.8"
7+
topology: ["sharded"]
8+
19
database_name: &database_name "withTransaction-tests"
210
collection_name: &collection_name "test"
311

@@ -7,6 +15,7 @@ tests:
715
-
816
# Session state will be COMMITTED when callback returns to withTransaction
917
description: withTransaction succeeds if callback commits
18+
useMultipleMongoses: true
1019
operations:
1120
-
1221
name: withTransaction
@@ -87,6 +96,7 @@ tests:
8796
-
8897
# Session state will be NO_TXN when callback returns to withTransaction
8998
description: withTransaction still succeeds if callback commits and runs extra op
99+
useMultipleMongoses: true
90100
operations:
91101
-
92102
name: withTransaction

tests/MongoDB.Driver.Tests/Specifications/transactions-convenient-api/tests/callback-retry.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.0",
5+
"topology": [
6+
"replicaset"
7+
]
8+
},
9+
{
10+
"minServerVersion": "4.1.8",
11+
"topology": [
12+
"sharded"
13+
]
14+
}
15+
],
216
"database_name": "withTransaction-tests",
317
"collection_name": "test",
418
"data": [],
@@ -177,6 +191,7 @@
177191
},
178192
{
179193
"description": "callback is not retried after non-transient error (DuplicateKeyError)",
194+
"useMultipleMongoses": true,
180195
"operations": [
181196
{
182197
"name": "withTransaction",

tests/MongoDB.Driver.Tests/Specifications/transactions-convenient-api/tests/callback-retry.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
runOn:
2+
-
3+
minServerVersion: "4.0"
4+
topology: ["replicaset"]
5+
-
6+
minServerVersion: "4.1.8"
7+
topology: ["sharded"]
8+
19
database_name: &database_name "withTransaction-tests"
210
collection_name: &collection_name "test"
311

@@ -127,6 +135,7 @@ tests:
127135
- { _id: 1 }
128136
-
129137
description: callback is not retried after non-transient error (DuplicateKeyError)
138+
useMultipleMongoses: true
130139
operations:
131140
-
132141
name: withTransaction

tests/MongoDB.Driver.Tests/Specifications/transactions-convenient-api/tests/commit-retry.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.0",
5+
"topology": [
6+
"replicaset"
7+
]
8+
},
9+
{
10+
"minServerVersion": "4.1.8",
11+
"topology": [
12+
"sharded"
13+
]
14+
}
15+
],
216
"database_name": "withTransaction-tests",
317
"collection_name": "test",
418
"data": [],

tests/MongoDB.Driver.Tests/Specifications/transactions-convenient-api/tests/commit-retry.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
runOn:
2+
-
3+
minServerVersion: "4.0"
4+
topology: ["replicaset"]
5+
-
6+
minServerVersion: "4.1.8"
7+
topology: ["sharded"]
8+
19
database_name: &database_name "withTransaction-tests"
210
collection_name: &collection_name "test"
311

0 commit comments

Comments
 (0)