Skip to content

Commit e230167

Browse files
kushagraThaparsimorenohtvaron3jeet1995scbedd
authored
Merging latest hotfix released back to main branch (Azure#39584)
* add new policy, add logic to use policy * added small test file I was using * initial regional endpoint work * groundwork * re-add AzureError logic, refactor, fix tests * Update _retry_utility.py * Updated location_cache with new design * Fixed key error with most_preferred_location * Update test_cosmos_http_logging_policy.py * Update _retry_utility.py * Added logic to refresh cache on previous endpoint usage * Added business logic update the regional endpoint based on success or failures * implementation * Update _retry_utility_async.py * fix some tests * changelog, versions, fixes * fixes * fix some tests * remove fake logic, count fix * fix some tests * Update _service_request_retry_policy.py * Update _retry_utility_async.py * retry utilities fixing * Update _retry_utility.py * additional enhancements * Update setup.py * Update _retry_utility_async.py * add tests, remove previous retry logic for ServiceRequestExceptions * clean up with finally * tests * retry utilities * disable tests * add logging to policies * GetDatabaseAccount Fix * Update _base.py * retry utilities fixes * Update _retry_utility.py * retry utulities part 34 * Update _service_request_retry_policy.py * remove extra logs * policy updates * Update _service_response_retry_policy.py * Update _service_response_retry_policy.py * policies updates and update operation types * trying out fixes * Update sdk/cosmos/azure-cosmos/CHANGELOG.md Co-authored-by: Abhijeet Mohanty <[email protected]> * Update sdk/cosmos/azure-cosmos/CHANGELOG.md Co-authored-by: Abhijeet Mohanty <[email protected]> * Skipped proxy test for debugging * annotation fix * Fixed some tests cases * test fixes * Update test_service_retry_policies_async.py * Fixed some mocking behavior * fixed pylint issues * Added aiohttp minimum dependency * Updated changelog and setup.py * Updated changelog * Add changelog and fix tests. * Fix tests * bootstrapping with global endpoint as previous for writes * Add headers and cleanup * cleanup and retry all service request headers * Don't retry on a none previous * Updated the business logic with current and previous, fixed database account refresh and some retry policies * fix client id * Reacting to comments * Added print statements and fixed some retry logic * Revert getDatabase in mark endpoint * Fixed some pylint and changelog issues * Fixed version * fix bug with type check, update tests * Update test_service_retry_policies_async.py * sync tests updates * Reacting to comments and fixing service request retry policy * Code review comments and pylint issues * Fixed tests and pylint * more sync mock tests - missing async copies * Fixed min aiohttp requirements * Update _retry_utility_async.py * Change to check operation type in operations * push initial GEM mock test * Update test_service_retry_policies.py * Fixed extra retries * sync tests * Update test_service_retry_policies_async.py * Fixed extra retries and relevant tests * Only delay retry by one second * async tests - need to split up inheritance ones since endpoint unavailable stops extra retries * Change retry strategy * add sub-class errors tests * change old tests, refactoring, fix mocking bleed * Fix a test * clear last routed location pythonic * Removed aiohttp dependency * catch import errors * Skipped global endpoint manager test for debugging * Fixed tests * Removed skips * fix live tests and print statements for debugging * cleanup of few tests * updated globaldb mock * Moved some of the high offer throughput tests to live tests * Fixed global endpoint retry async test * Tried fixing global endpoint retry async test * no swaps on success test * fix import * Tried fixing global endpoint retry async test * Added separate split live tests * Added live platform matrix * some test fixes * Fixed live test pipeline * Moved test resource id to cosmosLong * Updated live tests * Running live tests with proper flag * testing logging experiments * fix tests * honor testmark argument through a safe environment variable, versus accessing the value directly * more test fixes * remove accidental log files * Fixed issues with swapping and retry policies * Fixed issues with swapping and retry policies * Marking endpoint as down fix * more test fixes * Remove print statements * Fixed some minor issues with emulator tests * split change feed tests * Fixed emulator tests * updated changelog * Fixed emulator tests again * Fixed emulator tests and event loop * vector/fts query tests * Fix session token live tests * hybrid search query fixes * Fixed live test name * fallback to regional * fix ci tests * Update conftest.py * Database accounts call will timeout in 5 seconds * Change timeouts and update docs * call updates to endpoint policy and location cache * Health check for endpoitns * database account retry policy * Fix parameter error * Retry on cosmos error fix * Retry on service request error fix * None checks for request in retry utilities * lowercase constructed regional endpoint * fix global endpoint as unhealthy * fix parsing test * Added logic for swapping on health check failed * Fixed log statement * fix pylint, docs, and remove print statements * fix pylint * fix some tests * Prepared for release * Increment package version after release of azure-cosmos (Azure#39570) * Moved container create tests to emulator * Fix timeout test * Optimized tests to run live tests with correct configs * Fixed some errors * combine session token split tests * Moved query split test to query * Update sdk/cosmos/azure-cosmos/test/test_latest_session_token_async.py Co-authored-by: Simon Moreno <[email protected]> * rename to async * remove unnecessary imports --------- Co-authored-by: Simon Moreno <[email protected]> Co-authored-by: tvaron3 <[email protected]> Co-authored-by: Abhijeet Mohanty <[email protected]> Co-authored-by: Tomas Varon Saldarriaga <[email protected]> Co-authored-by: Scott Beddall <[email protected]> Co-authored-by: Azure SDK Bot <[email protected]> Co-authored-by: Tomas Varon <[email protected]>
1 parent 5aacaae commit e230167

24 files changed

+265
-299
lines changed

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
## Release History
22

3+
### 4.9.1b4 (Unreleased)
4+
5+
#### Features Added
6+
7+
#### Breaking Changes
8+
9+
#### Bugs Fixed
10+
11+
#### Other Changes
12+
313
### 4.9.1b3 (2025-02-04)
414

515
#### Features Added

sdk/cosmos/azure-cosmos/azure/cosmos/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
# SOFTWARE.
2121

22-
VERSION = "4.9.1b3"
22+
VERSION = "4.9.1b4"

sdk/cosmos/azure-cosmos/test/test_auto_scale.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from azure.cosmos import CosmosClient, cosmos_client
1212
from azure.cosmos import ThroughputProperties, PartitionKey
1313

14-
@pytest.mark.cosmosSplit
14+
@pytest.mark.cosmosLong
1515
class TestAutoScale(unittest.TestCase):
1616
client: CosmosClient = None
1717
host = test_config.TestConfig.host

sdk/cosmos/azure-cosmos/test/test_auto_scale_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from azure.cosmos import ThroughputProperties, PartitionKey
1212
from azure.cosmos.aio import CosmosClient, DatabaseProxy
1313

14-
@pytest.mark.cosmosSplit
14+
@pytest.mark.cosmosLong
1515
class TestAutoScaleAsync(unittest.IsolatedAsyncioTestCase):
1616
host = test_config.TestConfig.host
1717
masterKey = test_config.TestConfig.masterKey
@@ -35,7 +35,7 @@ async def asyncSetUp(self):
3535
self.client = CosmosClient(self.host, self.masterKey)
3636
self.created_database = self.client.get_database_client(self.TEST_DATABASE_ID)
3737

38-
async def tearDown(self):
38+
async def asyncTearDown(self):
3939
await self.client.close()
4040

4141
async def test_autoscale_create_container_async(self):

sdk/cosmos/azure-cosmos/test/test_change_feed_split.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,8 @@ def test_query_change_feed_with_split(self):
4646
assert len(iter_list) == 1
4747
continuation = created_collection.client_connection.last_response_headers['etag']
4848

49-
print("Triggering a split in test_query_change_feed_with_split")
50-
created_collection.replace_throughput(11000)
51-
print("changed offer to 11k")
52-
print("--------------------------------")
53-
print("Waiting for split to complete")
54-
start_time = time.time()
49+
test_config.TestConfig.trigger_split(created_collection, 11000)
5550

56-
while True:
57-
offer = created_collection.get_throughput()
58-
if offer.properties['content'].get('isOfferReplacePending', False):
59-
if time.time() - start_time > 60 * 25: # timeout test at 25 minutes
60-
unittest.skip("Partition split didn't complete in time.")
61-
else:
62-
print("Waiting for split to complete")
63-
time.sleep(60)
64-
else:
65-
break
66-
67-
print("Split in test_query_change_feed_with_split has completed")
6851
print("creating few more documents")
6952
new_documents = [{'pk': 'pk2', 'id': 'doc2'}, {'pk': 'pk3', 'id': 'doc3'}, {'pk': 'pk4', 'id': 'doc4'}]
7053
expected_ids = ['doc2', 'doc3', 'doc4']

sdk/cosmos/azure-cosmos/test/test_change_feed_split_async.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def asyncSetUp(self):
3636
self.client = CosmosClient(self.host, self.masterKey)
3737
self.created_database = self.client.get_database_client(self.TEST_DATABASE_ID)
3838

39-
async def tearDown(self):
39+
async def asyncTearDown(self):
4040
await self.client.close()
4141

4242
async def test_query_change_feed_with_split_async(self):
@@ -59,25 +59,8 @@ async def test_query_change_feed_with_split_async(self):
5959
assert len(iter_list) == 1
6060
continuation = created_collection.client_connection.last_response_headers['etag']
6161

62-
print("Triggering a split in test_query_change_feed_with_split")
63-
await created_collection.replace_throughput(11000)
64-
print("changed offer to 11k")
65-
print("--------------------------------")
66-
print("Waiting for split to complete")
67-
start_time = time.time()
68-
69-
while True:
70-
offer = await created_collection.get_throughput()
71-
if offer.properties['content'].get('isOfferReplacePending', False):
72-
if time.time() - start_time > 60 * 25: # timeout test at 25 minutes
73-
unittest.skip("Partition split didn't complete in time.")
74-
else:
75-
print("Waiting for split to complete")
76-
time.sleep(60)
77-
else:
78-
break
79-
80-
print("Split in test_query_change_feed_with_split has completed")
62+
await test_config.TestConfig.trigger_split_async(created_collection, 11000)
63+
8164
print("creating few more documents")
8265
new_documents = [{'pk': 'pk2', 'id': 'doc2'}, {'pk': 'pk3', 'id': 'doc3'}, {'pk': 'pk4', 'id': 'doc4'}]
8366
expected_ids = ['doc2', 'doc3', 'doc4']

sdk/cosmos/azure-cosmos/test/test_config.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import collections
55
import os
66
import time
7+
import unittest
78
import uuid
89

910
from azure.cosmos.cosmos_client import CosmosClient
@@ -173,6 +174,48 @@ async def _validate_offset_limit(cls, created_collection, query, results):
173174
query_iterable = created_collection.query_items(query=query)
174175
assert list(map(lambda doc: doc['pk'], [item async for item in query_iterable])) == results
175176

177+
@staticmethod
178+
def trigger_split(container, throughput):
179+
print("Triggering a split in session token helpers")
180+
container.replace_throughput(throughput)
181+
print("changed offer to 11k")
182+
print("--------------------------------")
183+
print("Waiting for split to complete")
184+
start_time = time.time()
185+
186+
while True:
187+
offer = container.get_throughput()
188+
if offer.properties['content'].get('isOfferReplacePending', False):
189+
if time.time() - start_time > 60 * 25: # timeout test at 25 minutes
190+
unittest.skip("Partition split didn't complete in time.")
191+
else:
192+
print("Waiting for split to complete")
193+
time.sleep(60)
194+
else:
195+
break
196+
print("Split in session token helpers has completed")
197+
198+
@staticmethod
199+
async def trigger_split_async(container, throughput):
200+
print("Triggering a split in session token helpers")
201+
await container.replace_throughput(throughput)
202+
print("changed offer to 11k")
203+
print("--------------------------------")
204+
print("Waiting for split to complete")
205+
start_time = time.time()
206+
207+
while True:
208+
offer = await container.get_throughput()
209+
if offer.properties['content'].get('isOfferReplacePending', False):
210+
if time.time() - start_time > 60 * 25: # timeout test at 25 minutes
211+
unittest.skip("Partition split didn't complete in time.")
212+
else:
213+
print("Waiting for split to complete")
214+
time.sleep(60)
215+
else:
216+
break
217+
print("Split in session token helpers has completed")
218+
176219

177220
def get_vector_indexing_policy(embedding_type):
178221
return {

sdk/cosmos/azure-cosmos/test/test_container_properties_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from azure.cosmos.partition_key import PartitionKey
1717

1818

19-
@pytest.mark.cosmosEmulator
19+
@pytest.mark.cosmosLong
2020
class TestContainerPropertiesCache(unittest.TestCase):
2121
"""Python CRUD Tests.
2222
"""

sdk/cosmos/azure-cosmos/test/test_container_properties_cache_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from azure.cosmos.partition_key import PartitionKey
1818

1919

20-
@pytest.mark.cosmosEmulator
20+
@pytest.mark.cosmosLong
2121
class TestContainerPropertiesCache(unittest.IsolatedAsyncioTestCase):
2222
"""Python CRUD Tests.
2323
"""
@@ -42,7 +42,7 @@ async def asyncSetUp(self):
4242
self.client = CosmosClient(self.host, self.masterKey)
4343
self.databaseForTest = await self.client.create_database_if_not_exists(self.configs.TEST_DATABASE_ID)
4444

45-
async def tearDown(self):
45+
async def asyncTearDown(self):
4646
await self.client.close()
4747

4848
async def test_container_properties_cache_async(self):

sdk/cosmos/azure-cosmos/test/test_crud_async.py

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ async def asyncSetUp(self):
8585
self.client = CosmosClient(self.host, self.masterKey)
8686
self.database_for_test = self.client.get_database_client(self.configs.TEST_DATABASE_ID)
8787

88-
async def tearDown(self):
88+
async def asyncTearDown(self):
8989
await self.client.close()
9090

9191
async def test_database_crud_async(self):
@@ -1708,37 +1708,24 @@ async def test_client_connection_retry_configuration_async(self):
17081708
total_time_for_three_retries = await self.initialize_client_with_connection_urllib_retry_config(3)
17091709
assert total_time_for_three_retries > total_time_for_two_retries
17101710

1711-
total_time_for_two_retries = await self.initialize_client_with_connection_core_retry_config(2)
1712-
total_time_for_three_retries = await self.initialize_client_with_connection_core_retry_config(3)
1713-
assert total_time_for_three_retries > total_time_for_two_retries
1714-
17151711
async def initialize_client_with_connection_urllib_retry_config(self, retries):
1716-
start_time = time.time()
1717-
try:
1718-
async with CosmosClient("https://localhost:9999", TestCRUDOperationsAsync.masterKey,
1719-
retry_total=retries, retry_connect=retries, retry_read=retries,
1720-
retry_backoff_max=0.3, retry_on_status_codes=[500, 502, 504]) as client:
1721-
print('Async initialization')
1722-
self.fail()
1723-
except AzureError as e:
1724-
end_time = time.time()
1725-
return end_time - start_time
1712+
async with CosmosClient(TestCRUDOperationsAsync.host, TestCRUDOperationsAsync.masterKey,
1713+
retry_total=retries, retry_connect=retries, retry_read=retries,
1714+
retry_backoff_max=0.3,
1715+
connection_timeout=.000000001) as client:
1716+
databaseForTest = client.get_database_client(self.configs.TEST_DATABASE_ID)
1717+
container = databaseForTest.get_container_client(self.configs.TEST_SINGLE_PARTITION_CONTAINER_ID)
1718+
start_time = time.time()
1719+
# client does a getDatabaseAccount on initialization, which will not time out because
1720+
# there is a forced timeout for those calls
17261721

1727-
async def initialize_client_with_connection_core_retry_config(self, retries):
1728-
start_time = time.time()
1729-
try:
1730-
async with CosmosClient(
1731-
"https://localhost:9999",
1732-
TestCRUDOperationsAsync.masterKey,
1733-
retry_total=retries,
1734-
retry_read=retries,
1735-
retry_connect=retries,
1736-
retry_status=retries) as client:
1722+
try:
1723+
await container.create_item(body={'id': str(uuid.uuid4()), 'name': 'sample'})
17371724
print('Async initialization')
1738-
self.fail()
1739-
except AzureError as e:
1740-
end_time = time.time()
1741-
return end_time - start_time
1725+
self.fail()
1726+
except AzureError as e:
1727+
end_time = time.time()
1728+
return end_time - start_time
17421729

17431730
# TODO: Skipping this test to debug later
17441731
@unittest.skip
@@ -2501,7 +2488,7 @@ async def priority_mock_execute_function(function, *args, **kwargs):
25012488
# Negative Test: Verify that if we send a value other than High or Low that it will not set the header value
25022489
# and result in bad request
25032490
try:
2504-
item2_read = created_container.read_item("item2", "pk2", priority="Medium")
2491+
item2_read = await created_container.read_item("item2", "pk2", priority="Medium")
25052492
except exceptions.CosmosHttpResponseError as e:
25062493
assert e.status_code == StatusCodes.BAD_REQUEST
25072494
_retry_utility_async.ExecuteFunctionAsync = self.OriginalExecuteFunction

0 commit comments

Comments
 (0)