|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# The MIT License (MIT) |
| 3 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 4 | +import unittest |
| 5 | +from concurrent.futures import ThreadPoolExecutor |
| 6 | +from unittest.mock import Mock |
| 7 | +from azure.cosmos._read_items_helper import ReadItemsHelperSync |
| 8 | + |
| 9 | + |
| 10 | +class TestMaxConcurrency(unittest.TestCase): |
| 11 | + """Unit tests for max_concurrency parameter behavior.""" |
| 12 | + |
| 13 | + def test_max_concurrency_none_uses_default(self): |
| 14 | + """Test that max_concurrency=None uses ThreadPoolExecutor's default.""" |
| 15 | + # Mock client connection |
| 16 | + mock_client = Mock() |
| 17 | + mock_client._routing_map_provider = Mock() |
| 18 | + mock_client._routing_map_provider.get_overlapping_ranges = Mock(return_value=[]) |
| 19 | + |
| 20 | + # Create helper with max_concurrency=None |
| 21 | + helper = ReadItemsHelperSync( |
| 22 | + client=mock_client, |
| 23 | + collection_link="/dbs/test/colls/test", |
| 24 | + items=[], |
| 25 | + options={}, |
| 26 | + partition_key_definition={"paths": ["/id"], "kind": "Hash"}, |
| 27 | + max_concurrency=None |
| 28 | + ) |
| 29 | + |
| 30 | + # Verify that max_concurrency is None |
| 31 | + self.assertIsNone(helper.max_concurrency) |
| 32 | + |
| 33 | + def test_max_concurrency_value_is_preserved(self): |
| 34 | + """Test that explicit max_concurrency value is preserved.""" |
| 35 | + # Mock client connection |
| 36 | + mock_client = Mock() |
| 37 | + mock_client._routing_map_provider = Mock() |
| 38 | + |
| 39 | + # Create helper with explicit max_concurrency |
| 40 | + helper = ReadItemsHelperSync( |
| 41 | + client=mock_client, |
| 42 | + collection_link="/dbs/test/colls/test", |
| 43 | + items=[], |
| 44 | + options={}, |
| 45 | + partition_key_definition={"paths": ["/id"], "kind": "Hash"}, |
| 46 | + max_concurrency=5 |
| 47 | + ) |
| 48 | + |
| 49 | + # Verify that max_concurrency is set correctly |
| 50 | + self.assertEqual(helper.max_concurrency, 5) |
| 51 | + |
| 52 | + |
| 53 | +if __name__ == '__main__': |
| 54 | + unittest.main() |
0 commit comments