|
31 | 31 | OvertCommandListener,
|
32 | 32 | SpecTestCreator,
|
33 | 33 | rs_or_single_client,
|
| 34 | + set_fail_point, |
34 | 35 | )
|
35 | 36 | from test.utils_spec_runner import SpecRunner
|
36 | 37 | from test.version import Version
|
|
40 | 41 | from bson.raw_bson import RawBSONDocument
|
41 | 42 | from bson.son import SON
|
42 | 43 | from pymongo.errors import (
|
| 44 | + AutoReconnect, |
43 | 45 | ConnectionFailure,
|
44 | 46 | OperationFailure,
|
45 | 47 | ServerSelectionTimeoutError,
|
@@ -469,6 +471,46 @@ def test_batch_splitting_retry_fails(self):
|
469 | 471 | self.assertEqual(final_txn, expected_txn)
|
470 | 472 | self.assertEqual(coll.find_one(projection={"_id": True}), {"_id": 1})
|
471 | 473 |
|
| 474 | + @client_context.require_multiple_mongoses |
| 475 | + @client_context.require_failCommand_fail_point |
| 476 | + def test_retryable_writes_in_sharded_cluster_multiple_available(self): |
| 477 | + fail_command = { |
| 478 | + "configureFailPoint": "failCommand", |
| 479 | + "mode": {"times": 1}, |
| 480 | + "data": { |
| 481 | + "failCommands": ["insert"], |
| 482 | + "closeConnection": True, |
| 483 | + "appName": "retryableWriteTest", |
| 484 | + }, |
| 485 | + } |
| 486 | + |
| 487 | + mongos_clients = [] |
| 488 | + |
| 489 | + for mongos in client_context.mongos_seeds().split(","): |
| 490 | + client = rs_or_single_client(mongos) |
| 491 | + set_fail_point(client, fail_command) |
| 492 | + self.addCleanup(client.close) |
| 493 | + mongos_clients.append(client) |
| 494 | + |
| 495 | + listener = OvertCommandListener() |
| 496 | + client = rs_or_single_client( |
| 497 | + client_context.mongos_seeds(), |
| 498 | + appName="retryableWriteTest", |
| 499 | + event_listeners=[listener], |
| 500 | + retryWrites=True, |
| 501 | + ) |
| 502 | + |
| 503 | + with self.assertRaises(AutoReconnect): |
| 504 | + client.t.t.insert_one({"x": 1}) |
| 505 | + |
| 506 | + # Disable failpoints on each mongos |
| 507 | + for client in mongos_clients: |
| 508 | + fail_command["mode"] = "off" |
| 509 | + set_fail_point(client, fail_command) |
| 510 | + |
| 511 | + self.assertEqual(len(listener.failed_events), 2) |
| 512 | + self.assertEqual(len(listener.succeeded_events), 0) |
| 513 | + |
472 | 514 |
|
473 | 515 | class TestWriteConcernError(IntegrationTest):
|
474 | 516 | RUN_ON_LOAD_BALANCER = True
|
|
0 commit comments