|
53 | 53 | from azure.cosmos.partition_key import PartitionKey
|
54 | 54 | import conftest
|
55 | 55 | from azure.cosmos import _retry_utility
|
| 56 | +from requests.packages.urllib3.util.retry import Retry |
| 57 | +from requests.exceptions import ConnectionError |
| 58 | + |
56 | 59 |
|
57 | 60 | pytestmark = pytest.mark.cosmosEmulator
|
58 | 61 |
|
@@ -1959,6 +1962,44 @@ def test_client_request_timeout(self):
|
1959 | 1962 | # client does a getDatabaseAccount on initialization, which will time out
|
1960 | 1963 | cosmos_client.CosmosClient(CRUDTests.host, CRUDTests.masterKey, "Session", connection_policy=connection_policy)
|
1961 | 1964 |
|
| 1965 | + def test_client_request_timeout_when_connection_retry_configuration_specified(self): |
| 1966 | + connection_policy = documents.ConnectionPolicy() |
| 1967 | + # making timeout 0 ms to make sure it will throw |
| 1968 | + connection_policy.RequestTimeout = 0 |
| 1969 | + connection_policy.ConnectionRetryConfiguration = Retry( |
| 1970 | + total=3, |
| 1971 | + read=3, |
| 1972 | + connect=3, |
| 1973 | + backoff_factor=0.3, |
| 1974 | + status_forcelist=(500, 502, 504) |
| 1975 | + ) |
| 1976 | + with self.assertRaises(Exception): |
| 1977 | + # client does a getDatabaseAccount on initialization, which will time out |
| 1978 | + cosmos_client.CosmosClient(CRUDTests.host, CRUDTests.masterKey, "Session", connection_policy=connection_policy) |
| 1979 | + |
| 1980 | + def test_client_connection_retry_configuration(self): |
| 1981 | + total_time_for_two_retries = self.initialize_client_with_connection_retry_config(2) |
| 1982 | + total_time_for_three_retries = self.initialize_client_with_connection_retry_config(3) |
| 1983 | + self.assertGreater(total_time_for_three_retries, total_time_for_two_retries) |
| 1984 | + |
| 1985 | + def initialize_client_with_connection_retry_config(self, retries): |
| 1986 | + from azure.core.exceptions import ServiceRequestError |
| 1987 | + connection_policy = documents.ConnectionPolicy() |
| 1988 | + connection_policy.ConnectionRetryConfiguration = Retry( |
| 1989 | + total=retries, |
| 1990 | + read=retries, |
| 1991 | + connect=retries, |
| 1992 | + backoff_factor=0.3, |
| 1993 | + status_forcelist=(500, 502, 504) |
| 1994 | + ) |
| 1995 | + start_time = time.time() |
| 1996 | + try: |
| 1997 | + cosmos_client.CosmosClient("https://localhost:9999", CRUDTests.masterKey, "Session", connection_policy=connection_policy) |
| 1998 | + self.fail() |
| 1999 | + except ServiceRequestError as e: |
| 2000 | + end_time = time.time() |
| 2001 | + return end_time - start_time |
| 2002 | + |
1962 | 2003 | def test_query_iterable_functionality(self):
|
1963 | 2004 | def __create_resources(client):
|
1964 | 2005 | """Creates resources for this test.
|
|
0 commit comments