@@ -65,28 +65,57 @@ async def test_service_request_retry_policy_async(self):
65
65
self .REGION3 : self .REGIONAL_ENDPOINT }
66
66
original_location_cache .read_regional_routing_contexts = [self .REGIONAL_ENDPOINT , self .REGIONAL_ENDPOINT ,
67
67
self .REGIONAL_ENDPOINT ]
68
+ expected_counter = len (original_location_cache .read_regional_routing_contexts )
68
69
try :
69
70
# Mock the function to return the ServiceRequestException we retry
70
71
mf = self .MockExecuteServiceRequestException ()
71
72
_retry_utility_async .ExecuteFunctionAsync = mf
72
73
await container .read_item (created_item ['id' ], created_item ['pk' ])
73
74
pytest .fail ("Exception was not raised." )
74
75
except ServiceRequestError :
75
- assert mf .counter == 3
76
+ assert mf .counter == expected_counter
77
+ finally :
78
+ _retry_utility_async .ExecuteFunctionAsync = self .original_execute_function
79
+
80
+ # Now we test with a query operation, iterating through items sends request without request object
81
+ # retry policy should eventually raise an exception as it should stop retrying with a max retry attempt
82
+ # equal to the available read region locations
83
+
84
+ # Change the location cache to have 3 preferred read regions and 3 available read endpoints by location
85
+ original_location_cache = mock_client .client_connection ._global_endpoint_manager .location_cache
86
+ original_location_cache .account_read_locations = [self .REGION1 , self .REGION2 , self .REGION3 ]
87
+ original_location_cache .available_read_regional_endpoints_by_locations = {
88
+ self .REGION1 : self .REGIONAL_ENDPOINT ,
89
+ self .REGION2 : self .REGIONAL_ENDPOINT ,
90
+ self .REGION3 : self .REGIONAL_ENDPOINT }
91
+ original_location_cache .read_regional_routing_contexts = [self .REGIONAL_ENDPOINT , self .REGIONAL_ENDPOINT ,
92
+ self .REGIONAL_ENDPOINT ]
93
+ expected_counter = len (original_location_cache .read_regional_routing_contexts )
94
+
95
+ try :
96
+ # Mock the function to return the ServiceRequestException we retry
97
+ mf = self .MockExecuteServiceRequestException ()
98
+ _retry_utility_async .ExecuteFunctionAsync = mf
99
+ items = [item async for item in container .query_items (query = "SELECT * FROM c" ,
100
+ partition_key = created_item ['pk' ])]
101
+ pytest .fail ("Exception was not raised." )
102
+ except ServiceRequestError :
103
+ assert mf .counter == expected_counter
76
104
finally :
77
105
_retry_utility_async .ExecuteFunctionAsync = self .original_execute_function
78
106
79
107
# Now we change the location cache to have only 1 preferred read region
80
108
original_location_cache .account_read_locations = [self .REGION1 ]
81
109
original_location_cache .read_regional_routing_contexts = [self .REGIONAL_ENDPOINT ]
110
+ expected_counter = len (original_location_cache .read_regional_routing_contexts )
82
111
try :
83
112
# Reset the function to reset the counter
84
113
mf = self .MockExecuteServiceRequestException ()
85
114
_retry_utility_async .ExecuteFunctionAsync = mf
86
115
await container .read_item (created_item ['id' ], created_item ['pk' ])
87
116
pytest .fail ("Exception was not raised." )
88
117
except ServiceRequestError :
89
- assert mf .counter == 1
118
+ assert mf .counter == expected_counter
90
119
finally :
91
120
_retry_utility_async .ExecuteFunctionAsync = self .original_execute_function
92
121
@@ -96,14 +125,15 @@ async def test_service_request_retry_policy_async(self):
96
125
original_location_cache .available_write_regional_endpoints_by_locations = {
97
126
self .REGION1 : self .REGIONAL_ENDPOINT ,
98
127
self .REGION2 : self .REGIONAL_ENDPOINT }
128
+ expected_counter = len (original_location_cache .write_regional_routing_contexts )
99
129
try :
100
130
# Reset the function to reset the counter
101
131
mf = self .MockExecuteServiceRequestException ()
102
132
_retry_utility_async .ExecuteFunctionAsync = mf
103
133
await container .create_item ({"id" : str (uuid .uuid4 ()), "pk" : str (uuid .uuid4 ())})
104
134
pytest .fail ("Exception was not raised." )
105
135
except ServiceRequestError :
106
- assert mf .counter == 2
136
+ assert mf .counter == expected_counter
107
137
finally :
108
138
_retry_utility_async .ExecuteFunctionAsync = self .original_execute_function
109
139
0 commit comments