Skip to content

Commit 9cccada

Browse files
committed
PYTHON-1794 Add runOn support to transaction tests
1 parent 244e7ff commit 9cccada

36 files changed

+502
-82
lines changed

test/__init__.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -545,20 +545,23 @@ def check_auth_with_sharding(self, func):
545545
"Auth with sharding requires MongoDB >= 2.0.0",
546546
func=func)
547547

548+
def is_topology_type(self, topologies):
549+
if 'single' in topologies and not (self.is_mongos or self.is_rs):
550+
return True
551+
if 'replicaset' in topologies and self.is_rs:
552+
return True
553+
if 'sharded' in topologies and self.is_mongos:
554+
return True
555+
return False
556+
548557
def require_cluster_type(self, topologies=[]):
549558
"""Run a test only if the client is connected to a cluster that
550559
conforms to one of the specified topologies. Acceptable topologies
551560
are 'single', 'replicaset', and 'sharded'."""
552561
def _is_valid_topology():
553-
if 'single' in topologies and not (self.is_mongos or self.is_rs):
554-
return True
555-
if 'replicaset' in topologies and self.is_rs:
556-
return True
557-
if 'sharded' in topologies and self.is_mongos:
558-
return True
559-
return False
562+
return self.is_topology_type(topologies)
560563
return self._require(
561-
_is_valid_topology,
564+
_is_valid_topology,
562565
"Cluster type not in %s" % (topologies))
563566

564567
def require_test_commands(self, func):

test/transactions-convenient-api/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",

test/transactions-convenient-api/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",

test/transactions-convenient-api/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",

test/transactions-convenient-api/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": [],

test/transactions-convenient-api/commit-transienttransactionerror-4.2.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.1.6",
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",
4-
"minServerVersion": "4.1.6",
518
"data": [],
619
"tests": [
720
{

test/transactions-convenient-api/commit-transienttransactionerror.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": [],

test/transactions-convenient-api/commit-writeconcernerror.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": [],

test/transactions-convenient-api/commit.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 commits after callback returns",
22+
"useMultipleMongoses": true,
823
"operations": [
924
{
1025
"name": "withTransaction",
@@ -123,6 +138,7 @@
123138
},
124139
{
125140
"description": "withTransaction commits after callback returns (second transaction)",
141+
"useMultipleMongoses": true,
126142
"operations": [
127143
{
128144
"name": "withTransaction",

test/transactions-convenient-api/transaction-options.json

Lines changed: 20 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 and no transaction options set",
22+
"useMultipleMongoses": true,
823
"operations": [
924
{
1025
"name": "withTransaction",
@@ -84,6 +99,7 @@
8499
},
85100
{
86101
"description": "withTransaction inherits transaction options from client",
102+
"useMultipleMongoses": true,
87103
"clientOptions": {
88104
"readConcernLevel": "local",
89105
"w": 1
@@ -171,6 +187,7 @@
171187
},
172188
{
173189
"description": "withTransaction inherits transaction options from defaultTransactionOptions",
190+
"useMultipleMongoses": true,
174191
"sessionOptions": {
175192
"session0": {
176193
"defaultTransactionOptions": {
@@ -266,6 +283,7 @@
266283
},
267284
{
268285
"description": "withTransaction explicit transaction options",
286+
"useMultipleMongoses": true,
269287
"operations": [
270288
{
271289
"name": "withTransaction",
@@ -357,6 +375,7 @@
357375
},
358376
{
359377
"description": "withTransaction explicit transaction options override defaultTransactionOptions",
378+
"useMultipleMongoses": true,
360379
"sessionOptions": {
361380
"session0": {
362381
"defaultTransactionOptions": {
@@ -460,6 +479,7 @@
460479
},
461480
{
462481
"description": "withTransaction explicit transaction options override client options",
482+
"useMultipleMongoses": true,
463483
"clientOptions": {
464484
"readConcernLevel": "majority",
465485
"w": "majority"

0 commit comments

Comments
 (0)