|
34 | 34 | AllowListEventListener,
|
35 | 35 | EventListener,
|
36 | 36 | OvertCommandListener,
|
| 37 | + delay, |
37 | 38 | ignore_deprecations,
|
38 | 39 | wait_until,
|
39 | 40 | )
|
|
44 | 45 | from pymongo.asynchronous.cursor import AsyncCursor, CursorType
|
45 | 46 | from pymongo.asynchronous.helpers import anext
|
46 | 47 | from pymongo.collation import Collation
|
47 |
| -from pymongo.errors import ExecutionTimeout, InvalidOperation, OperationFailure |
| 48 | +from pymongo.errors import ExecutionTimeout, InvalidOperation, OperationFailure, PyMongoError |
48 | 49 | from pymongo.operations import _IndexList
|
49 | 50 | from pymongo.read_concern import ReadConcern
|
50 | 51 | from pymongo.read_preferences import ReadPreference
|
@@ -1410,6 +1411,18 @@ async def test_to_list_length(self):
|
1410 | 1411 | docs = await c.to_list(3)
|
1411 | 1412 | self.assertEqual(len(docs), 2)
|
1412 | 1413 |
|
| 1414 | + async def test_to_list_csot_applied(self): |
| 1415 | + client = await self.async_single_client(timeoutMS=500) |
| 1416 | + # Initialize the client with a larger timeout to help make test less flakey |
| 1417 | + with pymongo.timeout(2): |
| 1418 | + await client.admin.command("ping") |
| 1419 | + coll = client.pymongo.test |
| 1420 | + await coll.insert_many([{} for _ in range(5)]) |
| 1421 | + cursor = coll.find({"$where": delay(1)}) |
| 1422 | + with self.assertRaises(PyMongoError) as ctx: |
| 1423 | + await cursor.to_list() |
| 1424 | + self.assertTrue(ctx.exception.timeout) |
| 1425 | + |
1413 | 1426 | @async_client_context.require_change_streams
|
1414 | 1427 | async def test_command_cursor_to_list(self):
|
1415 | 1428 | # Set maxAwaitTimeMS=1 to speed up the test.
|
@@ -1439,6 +1452,25 @@ async def test_command_cursor_to_list_length(self):
|
1439 | 1452 | result = await db.test.aggregate([pipeline])
|
1440 | 1453 | self.assertEqual(len(await result.to_list(1)), 1)
|
1441 | 1454 |
|
| 1455 | + @async_client_context.require_failCommand_blockConnection |
| 1456 | + async def test_command_cursor_to_list_csot_applied(self): |
| 1457 | + client = await self.async_single_client(timeoutMS=500) |
| 1458 | + # Initialize the client with a larger timeout to help make test less flakey |
| 1459 | + with pymongo.timeout(2): |
| 1460 | + await client.admin.command("ping") |
| 1461 | + coll = client.pymongo.test |
| 1462 | + await coll.insert_many([{} for _ in range(5)]) |
| 1463 | + fail_command = { |
| 1464 | + "configureFailPoint": "failCommand", |
| 1465 | + "mode": {"times": 5}, |
| 1466 | + "data": {"failCommands": ["getMore"], "blockConnection": True, "blockTimeMS": 1000}, |
| 1467 | + } |
| 1468 | + cursor = await coll.aggregate([], batchSize=1) |
| 1469 | + async with self.fail_point(fail_command): |
| 1470 | + with self.assertRaises(PyMongoError) as ctx: |
| 1471 | + await cursor.to_list() |
| 1472 | + self.assertTrue(ctx.exception.timeout) |
| 1473 | + |
1442 | 1474 |
|
1443 | 1475 | class TestRawBatchCursor(AsyncIntegrationTest):
|
1444 | 1476 | async def test_find_raw(self):
|
|
0 commit comments