@@ -65,28 +65,57 @@ async def test_service_request_retry_policy_async(self):
6565 self .REGION3 : self .REGIONAL_ENDPOINT }
6666 original_location_cache .read_regional_routing_contexts = [self .REGIONAL_ENDPOINT , self .REGIONAL_ENDPOINT ,
6767 self .REGIONAL_ENDPOINT ]
68+ expected_counter = len (original_location_cache .read_regional_routing_contexts )
6869 try :
6970 # Mock the function to return the ServiceRequestException we retry
7071 mf = self .MockExecuteServiceRequestException ()
7172 _retry_utility_async .ExecuteFunctionAsync = mf
7273 await container .read_item (created_item ['id' ], created_item ['pk' ])
7374 pytest .fail ("Exception was not raised." )
7475 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
76104 finally :
77105 _retry_utility_async .ExecuteFunctionAsync = self .original_execute_function
78106
79107 # Now we change the location cache to have only 1 preferred read region
80108 original_location_cache .account_read_locations = [self .REGION1 ]
81109 original_location_cache .read_regional_routing_contexts = [self .REGIONAL_ENDPOINT ]
110+ expected_counter = len (original_location_cache .read_regional_routing_contexts )
82111 try :
83112 # Reset the function to reset the counter
84113 mf = self .MockExecuteServiceRequestException ()
85114 _retry_utility_async .ExecuteFunctionAsync = mf
86115 await container .read_item (created_item ['id' ], created_item ['pk' ])
87116 pytest .fail ("Exception was not raised." )
88117 except ServiceRequestError :
89- assert mf .counter == 1
118+ assert mf .counter == expected_counter
90119 finally :
91120 _retry_utility_async .ExecuteFunctionAsync = self .original_execute_function
92121
@@ -96,14 +125,15 @@ async def test_service_request_retry_policy_async(self):
96125 original_location_cache .available_write_regional_endpoints_by_locations = {
97126 self .REGION1 : self .REGIONAL_ENDPOINT ,
98127 self .REGION2 : self .REGIONAL_ENDPOINT }
128+ expected_counter = len (original_location_cache .write_regional_routing_contexts )
99129 try :
100130 # Reset the function to reset the counter
101131 mf = self .MockExecuteServiceRequestException ()
102132 _retry_utility_async .ExecuteFunctionAsync = mf
103133 await container .create_item ({"id" : str (uuid .uuid4 ()), "pk" : str (uuid .uuid4 ())})
104134 pytest .fail ("Exception was not raised." )
105135 except ServiceRequestError :
106- assert mf .counter == 2
136+ assert mf .counter == expected_counter
107137 finally :
108138 _retry_utility_async .ExecuteFunctionAsync = self .original_execute_function
109139
0 commit comments