|
20 | 20 | from test.asynchronous.utils_spec_runner import AsyncSpecRunner
|
21 | 21 |
|
22 | 22 | from gridfs.asynchronous.grid_file import AsyncGridFS, AsyncGridFSBucket
|
| 23 | +from pymongo.asynchronous.pool import PoolState |
| 24 | +from pymongo.server_selectors import writable_server_selector |
23 | 25 |
|
24 | 26 | sys.path[0:0] = [""]
|
25 | 27 |
|
|
39 | 41 | from pymongo.asynchronous.cursor import AsyncCursor
|
40 | 42 | from pymongo.asynchronous.helpers import anext
|
41 | 43 | from pymongo.errors import (
|
| 44 | + AutoReconnect, |
42 | 45 | CollectionInvalid,
|
43 | 46 | ConfigurationError,
|
44 | 47 | ConnectionFailure,
|
@@ -394,6 +397,22 @@ async def find_raw_batches(*args, **kwargs):
|
394 | 397 | if isinstance(res, (AsyncCommandCursor, AsyncCursor)):
|
395 | 398 | await res.to_list()
|
396 | 399 |
|
| 400 | + @async_client_context.require_transactions |
| 401 | + async def test_transaction_pool_cleared_error_labelled_transient(self): |
| 402 | + c = await self.async_single_client() |
| 403 | + |
| 404 | + with self.assertRaises(AutoReconnect) as context: |
| 405 | + async with c.start_session() as session: |
| 406 | + async with await session.start_transaction(): |
| 407 | + server = await c._select_server(writable_server_selector, session, "test") |
| 408 | + # Pause the server's pool, causing it to fail connection checkout. |
| 409 | + server.pool.state = PoolState.PAUSED |
| 410 | + async with c._checkout(server, session): |
| 411 | + pass |
| 412 | + |
| 413 | + # Verify that the TransientTransactionError label is present in the error. |
| 414 | + self.assertTrue(context.exception.has_error_label("TransientTransactionError")) |
| 415 | + |
397 | 416 |
|
398 | 417 | class PatchSessionTimeout:
|
399 | 418 | """Patches the client_session's with_transaction timeout for testing."""
|
|
0 commit comments