Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions sdk/cosmos/azure-cosmos/tests/test_availability_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import uuid
from concurrent.futures import ThreadPoolExecutor
from typing import Optional, Any, Union
from unittest.mock import patch

import pytest
from azure.core.exceptions import ServiceResponseError
Expand Down Expand Up @@ -716,9 +717,12 @@ def test_no_cross_region_request_with_retry_write_disabled(self, operation):
@pytest.mark.parametrize("operation", [READ, QUERY_PK, CHANGE_FEED, CREATE, UPSERT, REPLACE, DELETE, PATCH, BATCH])
def test_per_partition_circular_breaker_with_cancelled_first_future(self, operation):
# QUERY, READ_ALL are not included because currently they are not targeting to a specific pkRange
os.environ["AZURE_COSMOS_ENABLE_CIRCUIT_BREAKER"] = "True"
os.environ["AZURE_COSMOS_CONSECUTIVE_ERROR_COUNT_TOLERATED_FOR_WRITE"] = "5"
os.environ["AZURE_COSMOS_CONSECUTIVE_ERROR_COUNT_TOLERATED_FOR_READ"] = "5"
env_patch = patch.dict(os.environ, {
"AZURE_COSMOS_ENABLE_CIRCUIT_BREAKER": "True",
"AZURE_COSMOS_CONSECUTIVE_ERROR_COUNT_TOLERATED_FOR_WRITE": "5",
"AZURE_COSMOS_CONSECUTIVE_ERROR_COUNT_TOLERATED_FOR_READ": "5",
})
env_patch.start()

try:
"""Test that when per partition circular breaker is enabled and after hitting the threshold, subsequent requests go directly to second region.
Expand Down Expand Up @@ -799,9 +803,7 @@ def test_per_partition_circular_breaker_with_cancelled_first_future(self, operat
availability_strategy=strategy)

finally:
del os.environ["AZURE_COSMOS_ENABLE_CIRCUIT_BREAKER"]
del os.environ["AZURE_COSMOS_CONSECUTIVE_ERROR_COUNT_TOLERATED_FOR_WRITE"]
del os.environ["AZURE_COSMOS_CONSECUTIVE_ERROR_COUNT_TOLERATED_FOR_READ"]
env_patch.stop()

self._clean_up_container(setup_with_fault_injection['db'].id, setup_with_fault_injection['col'].id)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import unittest
import uuid
from typing import Optional, Any, Union
from unittest.mock import patch

import pytest
import pytest_asyncio
Expand Down Expand Up @@ -847,9 +848,12 @@ async def test_no_cross_region_request_with_exclude_regions_async(self, operatio
@pytest.mark.parametrize("operation", [READ, QUERY_PK, CHANGE_FEED, CREATE, UPSERT, REPLACE, DELETE, PATCH, BATCH])
async def test_per_partition_circular_breaker_with_cancelled_first_future_async(self, operation, setup):
# QUERY, READ_ALL are not included because currently they are not targeting to a specific pkRange
os.environ["AZURE_COSMOS_ENABLE_CIRCUIT_BREAKER"] = "True"
os.environ["AZURE_COSMOS_CONSECUTIVE_ERROR_COUNT_TOLERATED_FOR_WRITE"] = "5"
os.environ["AZURE_COSMOS_CONSECUTIVE_ERROR_COUNT_TOLERATED_FOR_READ"] = "5"
env_patch = patch.dict(os.environ, {
"AZURE_COSMOS_ENABLE_CIRCUIT_BREAKER": "True",
"AZURE_COSMOS_CONSECUTIVE_ERROR_COUNT_TOLERATED_FOR_WRITE": "5",
"AZURE_COSMOS_CONSECUTIVE_ERROR_COUNT_TOLERATED_FOR_READ": "5",
})
env_patch.start()

try:
"""Test that when per partition circular breaker is enabled and after hitting the threshold, subsequent requests go directly to second region.
Expand Down Expand Up @@ -938,9 +942,7 @@ async def test_per_partition_circular_breaker_with_cancelled_first_future_async(
await setup_with_fault_injection['client'].close()
await setup_without_fault['client'].close()
finally:
del os.environ["AZURE_COSMOS_ENABLE_CIRCUIT_BREAKER"]
del os.environ["AZURE_COSMOS_CONSECUTIVE_ERROR_COUNT_TOLERATED_FOR_WRITE"]
del os.environ["AZURE_COSMOS_CONSECUTIVE_ERROR_COUNT_TOLERATED_FOR_READ"]
env_patch.stop()
await self._clean_up_container(setup['client_without_fault'], setup_with_fault_injection['db'].id, setup_with_fault_injection['col'].id)

@pytest.mark.asyncio
Expand Down
Loading