|
15 | 15 | """Test retryable writes."""
|
16 | 16 | from __future__ import annotations
|
17 | 17 |
|
| 18 | +import asyncio |
18 | 19 | import copy
|
19 | 20 | import pprint
|
20 | 21 | import sys
|
|
71 | 72 |
|
72 | 73 |
|
73 | 74 | class InsertEventListener(EventListener):
|
74 |
| - async def succeeded(self, event: CommandSucceededEvent) -> None: |
| 75 | + def succeeded(self, event: CommandSucceededEvent) -> None: |
75 | 76 | super().succeeded(event)
|
76 | 77 | if (
|
77 | 78 | event.command_name == "insert"
|
78 | 79 | and event.reply.get("writeConcernError", {}).get("code", None) == 91
|
79 | 80 | ):
|
80 |
| - await async_client_context.client.admin.command( |
81 |
| - { |
82 |
| - "configureFailPoint": "failCommand", |
83 |
| - "mode": {"times": 1}, |
84 |
| - "data": { |
85 |
| - "errorCode": 10107, |
86 |
| - "errorLabels": ["RetryableWriteError", "NoWritesPerformed"], |
87 |
| - "failCommands": ["insert"], |
88 |
| - }, |
89 |
| - } |
| 81 | + asyncio.run( |
| 82 | + async_client_context.client.admin.command( |
| 83 | + { |
| 84 | + "configureFailPoint": "failCommand", |
| 85 | + "mode": {"times": 1}, |
| 86 | + "data": { |
| 87 | + "errorCode": 10107, |
| 88 | + "errorLabels": ["RetryableWriteError", "NoWritesPerformed"], |
| 89 | + "failCommands": ["insert"], |
| 90 | + }, |
| 91 | + } |
| 92 | + ) |
90 | 93 | )
|
91 | 94 |
|
92 | 95 |
|
@@ -372,7 +375,7 @@ async def test_batch_splitting(self):
|
372 | 375 | # With OP_MSG 3 inserts are one batch. 2 updates another.
|
373 | 376 | # 2 deletes a third.
|
374 | 377 | self.assertEqual(len(self.listener.started_events), 6)
|
375 |
| - await self.assertEqual(coll.find_one(), {"_id": 1, "count": 1}) |
| 378 | + self.assertEqual(await coll.find_one(), {"_id": 1, "count": 1}) |
376 | 379 | # Assert the final result
|
377 | 380 | expected_result = {
|
378 | 381 | "writeErrors": [],
|
@@ -434,7 +437,7 @@ async def test_batch_splitting_retry_fails(self):
|
434 | 437 | self.assertEqual(started[1].command, started[2].command)
|
435 | 438 | final_txn = session._transaction_id
|
436 | 439 | self.assertEqual(final_txn, expected_txn)
|
437 |
| - await self.assertEqual(coll.find_one(projection={"_id": True}), {"_id": 1}) |
| 440 | + self.assertEqual(await coll.find_one(projection={"_id": True}), {"_id": 1}) |
438 | 441 |
|
439 | 442 | @async_client_context.require_multiple_mongoses
|
440 | 443 | @async_client_context.require_failCommand_fail_point
|
|
0 commit comments