Skip to content

Commit 8ae8fbe

Browse files
CSHARP-2577: Update Transactions count test for MongoDB >= 4.0.7.
1 parent 501208f commit 8ae8fbe

File tree

5 files changed

+198
-139
lines changed

5 files changed

+198
-139
lines changed

tests/MongoDB.Driver.Tests/Specifications/transactions/TransactionTestRunner.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
using System;
1717
using System.Collections.Generic;
1818
using System.Linq;
19-
using System.Net;
2019
using System.Threading;
2120
using System.Threading.Tasks;
2221
using FluentAssertions;
2322
using MongoDB.Bson;
2423
using MongoDB.Bson.TestHelpers.JsonDrivenTests;
25-
using MongoDB.Bson.TestHelpers.XunitExtensions;
2624
using MongoDB.Driver.Core;
2725
using MongoDB.Driver.Core.Bindings;
2826
using MongoDB.Driver.Core.Clusters;
@@ -136,6 +134,12 @@ private void Run(BsonDocument shared, BsonDocument test)
136134
throw new SkipException($"Test skipped because {test["skipReason"]}.");
137135
}
138136

137+
if (shared.TryGetValue("runOn", out var runOn))
138+
{
139+
RequireServer.Check().RunOn(runOn.AsBsonArray);
140+
}
141+
142+
// support for "topology" will be removed soon when the JSON files are all updated to the newer format that no longer uses "topology"
139143
if (shared.TryGetValue("topology", out var topology))
140144
{
141145
CheckClusterTopology(topology.AsBsonArray);
@@ -147,7 +151,8 @@ private void Run(BsonDocument shared, BsonDocument test)
147151
"collection_name",
148152
"data",
149153
"tests",
150-
"topology");
154+
"topology",
155+
"runOn");
151156
JsonDrivenHelper.EnsureAllFieldsAreValid(test,
152157
"description",
153158
"clientOptions",
@@ -259,15 +264,15 @@ private void PrimeShardRoutersWithDistinctCommand()
259264
collection.Distinct<BsonValue>("_id", "{ }");
260265
}
261266
}
262-
267+
263268
private DisposableMongoClient CreateDisposableClient(BsonDocument test, EventCapturer eventCapturer, bool useMultipleShardRouters)
264269
{
265270
return DriverTestConfiguration.CreateDisposableClient(
266271
(MongoClientSettings settings) =>
267272
{
268273
ConfigureClientSettings(settings, test);
269274
settings.ClusterConfigurator = c => c.Subscribe(eventCapturer);
270-
},
275+
},
271276
useMultipleShardRouters);
272277
}
273278

@@ -378,7 +383,7 @@ private DisposableBundle ConfigureFailPointOnPrimaryOrShardRoutersIfNeeded(IMong
378383
var primary = cluster.SelectServer(WritableServerSelector.Instance, CancellationToken.None);
379384
failPointServers = new List<IServer> { primary };
380385
break;
381-
386+
382387
case ClusterType.Sharded:
383388
failPointServers =
384389
cluster.Description.Servers
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.0.2",
5+
"topology": [
6+
"replicaset"
7+
]
8+
},
9+
{
10+
"minServerVersion": "4.1.8",
11+
"topology": [
12+
"sharded"
13+
]
14+
}
15+
],
16+
"database_name": "transaction-tests",
17+
"collection_name": "test",
18+
"data": [
19+
{
20+
"_id": 1
21+
},
22+
{
23+
"_id": 2
24+
},
25+
{
26+
"_id": 3
27+
},
28+
{
29+
"_id": 4
30+
}
31+
],
32+
"tests": [
33+
{
34+
"description": "count",
35+
"operations": [
36+
{
37+
"name": "startTransaction",
38+
"object": "session0"
39+
},
40+
{
41+
"name": "count",
42+
"object": "collection",
43+
"arguments": {
44+
"session": "session0",
45+
"filter": {
46+
"_id": 1
47+
}
48+
},
49+
"result": {
50+
"errorCodeName": "OperationNotSupportedInTransaction",
51+
"errorLabelsOmit": [
52+
"TransientTransactionError",
53+
"UnknownTransactionCommitResult"
54+
]
55+
}
56+
},
57+
{
58+
"name": "abortTransaction",
59+
"object": "session0"
60+
}
61+
],
62+
"expectations": [
63+
{
64+
"command_started_event": {
65+
"command": {
66+
"count": "test",
67+
"query": {
68+
"_id": 1
69+
},
70+
"readConcern": null,
71+
"lsid": "session0",
72+
"txnNumber": {
73+
"$numberLong": "1"
74+
},
75+
"startTransaction": true,
76+
"autocommit": false,
77+
"writeConcern": null
78+
},
79+
"command_name": "count",
80+
"database_name": "transaction-tests"
81+
}
82+
},
83+
{
84+
"command_started_event": {
85+
"command": {
86+
"abortTransaction": 1,
87+
"lsid": "session0",
88+
"txnNumber": {
89+
"$numberLong": "1"
90+
},
91+
"startTransaction": null,
92+
"autocommit": false,
93+
"writeConcern": null
94+
},
95+
"command_name": "abortTransaction",
96+
"database_name": "admin"
97+
}
98+
}
99+
],
100+
"outcome": {
101+
"collection": {
102+
"data": [
103+
{
104+
"_id": 1
105+
},
106+
{
107+
"_id": 2
108+
},
109+
{
110+
"_id": 3
111+
},
112+
{
113+
"_id": 4
114+
}
115+
]
116+
}
117+
}
118+
}
119+
]
120+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
runOn:
2+
# SERVER-35388 introduced OperationNotSupportedInTransaction in 4.0.2
3+
-
4+
minServerVersion: "4.0.2"
5+
topology: ["replicaset"]
6+
-
7+
minServerVersion: "4.1.8"
8+
topology: ["sharded"]
9+
10+
database_name: &database_name "transaction-tests"
11+
collection_name: &collection_name "test"
12+
13+
data: &data
14+
- {_id: 1}
15+
- {_id: 2}
16+
- {_id: 3}
17+
- {_id: 4}
18+
19+
tests:
20+
- description: count
21+
22+
operations:
23+
- name: startTransaction
24+
object: session0
25+
- name: count
26+
object: collection
27+
arguments:
28+
session: session0
29+
filter:
30+
_id: 1
31+
result:
32+
errorCodeName: OperationNotSupportedInTransaction
33+
errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"]
34+
- name: abortTransaction
35+
object: session0
36+
37+
expectations:
38+
- command_started_event:
39+
command:
40+
count: *collection_name
41+
query:
42+
_id: 1
43+
readConcern:
44+
lsid: session0
45+
txnNumber:
46+
$numberLong: "1"
47+
startTransaction: true
48+
autocommit: false
49+
writeConcern:
50+
command_name: count
51+
database_name: *database_name
52+
- command_started_event:
53+
command:
54+
abortTransaction: 1
55+
lsid: session0
56+
txnNumber:
57+
$numberLong: "1"
58+
startTransaction:
59+
autocommit: false
60+
writeConcern:
61+
command_name: abortTransaction
62+
database_name: admin
63+
64+
outcome:
65+
collection:
66+
data:
67+
*data

tests/MongoDB.Driver.Tests/Specifications/transactions/tests/reads.json

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -87,92 +87,6 @@
8787
}
8888
}
8989
},
90-
{
91-
"description": "count",
92-
"operations": [
93-
{
94-
"name": "startTransaction",
95-
"object": "session0"
96-
},
97-
{
98-
"name": "count",
99-
"object": "collection",
100-
"arguments": {
101-
"session": "session0",
102-
"filter": {
103-
"_id": 1
104-
}
105-
},
106-
"result": {
107-
"errorContains": "Cannot run 'count' in a multi-document transaction",
108-
"errorLabelsOmit": [
109-
"TransientTransactionError",
110-
"UnknownTransactionCommitResult"
111-
]
112-
}
113-
},
114-
{
115-
"name": "abortTransaction",
116-
"object": "session0"
117-
}
118-
],
119-
"expectations": [
120-
{
121-
"command_started_event": {
122-
"command": {
123-
"count": "test",
124-
"query": {
125-
"_id": 1
126-
},
127-
"readConcern": null,
128-
"lsid": "session0",
129-
"txnNumber": {
130-
"$numberLong": "1"
131-
},
132-
"startTransaction": true,
133-
"autocommit": false,
134-
"writeConcern": null
135-
},
136-
"command_name": "count",
137-
"database_name": "transaction-tests"
138-
}
139-
},
140-
{
141-
"command_started_event": {
142-
"command": {
143-
"abortTransaction": 1,
144-
"lsid": "session0",
145-
"txnNumber": {
146-
"$numberLong": "1"
147-
},
148-
"startTransaction": null,
149-
"autocommit": false,
150-
"writeConcern": null
151-
},
152-
"command_name": "abortTransaction",
153-
"database_name": "admin"
154-
}
155-
}
156-
],
157-
"outcome": {
158-
"collection": {
159-
"data": [
160-
{
161-
"_id": 1
162-
},
163-
{
164-
"_id": 2
165-
},
166-
{
167-
"_id": 3
168-
},
169-
{
170-
"_id": 4
171-
}
172-
]
173-
}
174-
}
175-
},
17690
{
17791
"description": "find",
17892
"operations": [

0 commit comments

Comments
 (0)