Skip to content

Commit ab73a7a

Browse files
ShaneHarveyajdavis
authored andcommitted
Re-sync transactions tests
1 parent b4f153a commit ab73a7a

13 files changed

+913
-39
lines changed

test/test_transactions.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,23 @@ def run_operation(self, sessions, collection, operation):
138138

139139
# Convert arguments to snake_case and handle special cases.
140140
arguments = operation['arguments']
141-
options = arguments.pop("options", {})
142-
for option_name in options:
143-
arguments[camel_to_snake(option_name)] = options[option_name]
144-
145141
pref = arguments.pop('readPreference', None)
146142
if pref:
147143
mode = read_pref_mode_from_name(pref['mode'])
148144
collection = collection.with_options(
149145
read_preference=make_read_preference(mode, None))
146+
write_c = arguments.pop('writeConcern', None)
147+
if write_c:
148+
collection = collection.with_options(
149+
write_concern=WriteConcern(**write_c))
150+
read_c = arguments.pop('readConcern', None)
151+
if read_c:
152+
collection = collection.with_options(
153+
read_concern=ReadConcern(**read_c))
154+
155+
options = arguments.pop("options", {})
156+
for option_name in options:
157+
arguments[camel_to_snake(option_name)] = options[option_name]
150158

151159
if name.endswith('_transaction'):
152160
cmd = getattr(session, name)
@@ -181,9 +189,9 @@ def run_operation(self, sessions, collection, operation):
181189
# Requires boolean returnDocument.
182190
elif arg_name == "returnDocument":
183191
arguments[c2s] = arguments[arg_name] == "After"
184-
elif arg_name == "readConcern":
192+
elif c2s == "read_concern":
185193
arguments[c2s] = ReadConcern(**arguments.pop(arg_name))
186-
elif arg_name == "writeConcern":
194+
elif c2s == "write_concern":
187195
arguments[c2s] = WriteConcern(**arguments.pop(arg_name))
188196
else:
189197
arguments[c2s] = arguments.pop(arg_name)

test/transactions/auto-start.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@
380380
"level": "snapshot",
381381
"afterClusterTime": 42
382382
},
383+
"lsid": "session0",
383384
"txnNumber": {
384385
"$numberLong": "2"
385386
},
@@ -456,9 +457,6 @@
456457
"name": "commitTransaction",
457458
"arguments": {
458459
"session": "session0"
459-
},
460-
"result": {
461-
"errorContains": "no transaction started"
462460
}
463461
}
464462
],

test/transactions/bulk.json

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,104 @@
510510
]
511511
}
512512
}
513+
},
514+
{
515+
"description": "operation writeConcern ignored for bulk",
516+
"operations": [
517+
{
518+
"name": "startTransaction",
519+
"arguments": {
520+
"session": "session0",
521+
"options": {
522+
"writeConcern": {
523+
"w": "majority"
524+
}
525+
}
526+
}
527+
},
528+
{
529+
"name": "bulkWrite",
530+
"arguments": {
531+
"requests": [
532+
{
533+
"name": "insertOne",
534+
"arguments": {
535+
"document": {
536+
"_id": 1
537+
}
538+
}
539+
}
540+
],
541+
"writeConcern": {
542+
"w": "majority"
543+
},
544+
"session": "session0"
545+
},
546+
"result": {
547+
"deletedCount": 0,
548+
"insertedIds": {
549+
"0": 1
550+
},
551+
"matchedCount": 0,
552+
"modifiedCount": 0,
553+
"upsertedCount": 0,
554+
"upsertedIds": {}
555+
}
556+
},
557+
{
558+
"name": "commitTransaction",
559+
"arguments": {
560+
"session": "session0"
561+
}
562+
}
563+
],
564+
"expectations": [
565+
{
566+
"command_started_event": {
567+
"command": {
568+
"insert": "test",
569+
"documents": [
570+
{
571+
"_id": 1
572+
}
573+
],
574+
"ordered": true,
575+
"readConcern": {
576+
"level": "snapshot"
577+
},
578+
"lsid": "session0",
579+
"txnNumber": {
580+
"$numberLong": "1"
581+
},
582+
"stmtId": 0,
583+
"startTransaction": true,
584+
"autocommit": false,
585+
"writeConcern": null
586+
},
587+
"command_name": "insert",
588+
"database_name": "transaction-tests"
589+
}
590+
},
591+
{
592+
"command_started_event": {
593+
"command": {
594+
"commitTransaction": 1,
595+
"lsid": "session0",
596+
"txnNumber": {
597+
"$numberLong": "1"
598+
},
599+
"stmtId": 1,
600+
"startTransaction": null,
601+
"autocommit": false,
602+
"writeConcern": {
603+
"w": "majority"
604+
}
605+
},
606+
"command_name": "commitTransaction",
607+
"database_name": "admin"
608+
}
609+
}
610+
]
513611
}
514612
]
515613
}

test/transactions/delete.json

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,138 @@
182182
]
183183
}
184184
}
185+
},
186+
{
187+
"description": "operation writeConcern ignored for delete",
188+
"operations": [
189+
{
190+
"name": "startTransaction",
191+
"arguments": {
192+
"session": "session0",
193+
"options": {
194+
"writeConcern": {
195+
"w": "majority"
196+
}
197+
}
198+
}
199+
},
200+
{
201+
"name": "deleteOne",
202+
"arguments": {
203+
"filter": {
204+
"_id": 1
205+
},
206+
"writeConcern": {
207+
"w": "majority"
208+
},
209+
"session": "session0"
210+
},
211+
"result": {
212+
"deletedCount": 1
213+
}
214+
},
215+
{
216+
"name": "deleteMany",
217+
"arguments": {
218+
"filter": {
219+
"_id": {
220+
"$lte": 3
221+
}
222+
},
223+
"writeConcern": {
224+
"w": "majority"
225+
},
226+
"session": "session0"
227+
},
228+
"result": {
229+
"deletedCount": 2
230+
}
231+
},
232+
{
233+
"name": "commitTransaction",
234+
"arguments": {
235+
"session": "session0"
236+
}
237+
}
238+
],
239+
"expectations": [
240+
{
241+
"command_started_event": {
242+
"command": {
243+
"delete": "test",
244+
"deletes": [
245+
{
246+
"q": {
247+
"_id": 1
248+
},
249+
"limit": 1
250+
}
251+
],
252+
"ordered": true,
253+
"readConcern": {
254+
"level": "snapshot"
255+
},
256+
"lsid": "session0",
257+
"txnNumber": {
258+
"$numberLong": "1"
259+
},
260+
"stmtId": 0,
261+
"startTransaction": true,
262+
"autocommit": false,
263+
"writeConcern": null
264+
},
265+
"command_name": "delete",
266+
"database_name": "transaction-tests"
267+
}
268+
},
269+
{
270+
"command_started_event": {
271+
"command": {
272+
"delete": "test",
273+
"deletes": [
274+
{
275+
"q": {
276+
"_id": {
277+
"$lte": 3
278+
}
279+
},
280+
"limit": 0
281+
}
282+
],
283+
"ordered": true,
284+
"lsid": "session0",
285+
"txnNumber": {
286+
"$numberLong": "1"
287+
},
288+
"stmtId": 1,
289+
"startTransaction": null,
290+
"autocommit": false,
291+
"writeConcern": null
292+
},
293+
"command_name": "delete",
294+
"database_name": "transaction-tests"
295+
}
296+
},
297+
{
298+
"command_started_event": {
299+
"command": {
300+
"commitTransaction": 1,
301+
"lsid": "session0",
302+
"txnNumber": {
303+
"$numberLong": "1"
304+
},
305+
"stmtId": 2,
306+
"startTransaction": null,
307+
"autocommit": false,
308+
"writeConcern": {
309+
"w": "majority"
310+
}
311+
},
312+
"command_name": "commitTransaction",
313+
"database_name": "admin"
314+
}
315+
}
316+
]
185317
}
186318
]
187319
}

test/transactions/findOneAndDelete.json

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,89 @@
127127
]
128128
}
129129
}
130+
},
131+
{
132+
"description": "operation writeConcern ignored for findOneAndDelete",
133+
"operations": [
134+
{
135+
"name": "startTransaction",
136+
"arguments": {
137+
"session": "session0",
138+
"options": {
139+
"writeConcern": {
140+
"w": "majority"
141+
}
142+
}
143+
}
144+
},
145+
{
146+
"name": "findOneAndDelete",
147+
"arguments": {
148+
"filter": {
149+
"_id": 3
150+
},
151+
"session": "session0",
152+
"writeConcern": {
153+
"w": "majority"
154+
}
155+
},
156+
"result": {
157+
"_id": 3
158+
}
159+
},
160+
{
161+
"name": "commitTransaction",
162+
"arguments": {
163+
"session": "session0"
164+
}
165+
}
166+
],
167+
"expectations": [
168+
{
169+
"command_started_event": {
170+
"command": {
171+
"findAndModify": "test",
172+
"query": {
173+
"_id": 3
174+
},
175+
"remove": true,
176+
"lsid": "session0",
177+
"txnNumber": {
178+
"$numberLong": "1"
179+
},
180+
"stmtId": 0,
181+
"startTransaction": true,
182+
"autocommit": false,
183+
"readConcern": {
184+
"level": "snapshot"
185+
},
186+
"writeConcern": null
187+
},
188+
"command_name": "findAndModify",
189+
"database_name": "transaction-tests"
190+
}
191+
},
192+
{
193+
"command_started_event": {
194+
"command": {
195+
"commitTransaction": 1,
196+
"lsid": "session0",
197+
"txnNumber": {
198+
"$numberLong": "1"
199+
},
200+
"stmtId": 1,
201+
"startTransaction": null,
202+
"autocommit": false,
203+
"readConcern": null,
204+
"writeConcern": {
205+
"w": "majority"
206+
}
207+
},
208+
"command_name": "commitTransaction",
209+
"database_name": "admin"
210+
}
211+
}
212+
]
130213
}
131214
]
132215
}

0 commit comments

Comments
 (0)