Merge "Expand retry handling on ratelimit response"

This commit is contained in:
Zuul 2022-08-19 00:43:25 +00:00 committed by Gerrit Code Review
commit c1f5e8b7c1
2 changed files with 31 additions and 25 deletions

View File

@ -1825,7 +1825,7 @@ class Connection:
self.http_conn = None
elif 500 <= err.http_status <= 599:
pass
elif self.retry_on_ratelimit and err.http_status == 498:
elif self.retry_on_ratelimit and err.http_status in (498, 429):
pass
else:
raise

View File

@ -2130,31 +2130,37 @@ class TestConnection(MockHttpTest):
pass
c.sleep = quick_sleep
# test retries
conn = c.Connection('http://www.test.com/auth/v1.0', 'asdf', 'asdf',
retry_on_ratelimit=True)
code_iter = [200] + [498] * (conn.retries + 1)
auth_resp_headers = {
'x-auth-token': 'asdf',
'x-storage-url': 'http://storage/v1/test',
}
c.http_connection = self.fake_http_connection(
*code_iter, headers=auth_resp_headers)
with self.assertRaises(c.ClientException) as exc_context:
conn.head_account()
self.assertIn('Account HEAD failed', str(exc_context.exception))
self.assertEqual(conn.attempts, conn.retries + 1)
def test_status_code(code):
# test retries
conn = c.Connection('http://www.test.com/auth/v1.0',
'asdf', 'asdf', retry_on_ratelimit=True)
code_iter = [200] + [code] * (conn.retries + 1)
auth_resp_headers = {
'x-auth-token': 'asdf',
'x-storage-url': 'http://storage/v1/test',
}
c.http_connection = self.fake_http_connection(
*code_iter, headers=auth_resp_headers)
with self.assertRaises(c.ClientException) as exc_context:
conn.head_account()
self.assertIn('Account HEAD failed', str(exc_context.exception))
self.assertEqual(code, exc_context.exception.http_status)
self.assertEqual(conn.attempts, conn.retries + 1)
# test default no-retry
c.http_connection = self.fake_http_connection(
200, 498,
headers=auth_resp_headers)
conn = c.Connection('http://www.test.com/auth/v1.0', 'asdf', 'asdf',
retry_on_ratelimit=False)
with self.assertRaises(c.ClientException) as exc_context:
conn.head_account()
self.assertIn('Account HEAD failed', str(exc_context.exception))
self.assertEqual(conn.attempts, 1)
# test default no-retry
c.http_connection = self.fake_http_connection(
200, code,
headers=auth_resp_headers)
conn = c.Connection('http://www.test.com/auth/v1.0',
'asdf', 'asdf', retry_on_ratelimit=False)
with self.assertRaises(c.ClientException) as exc_context:
conn.head_account()
self.assertIn('Account HEAD failed', str(exc_context.exception))
self.assertEqual(code, exc_context.exception.http_status)
self.assertEqual(conn.attempts, 1)
test_status_code(498)
test_status_code(429)
def test_retry_with_socket_error(self):
def quick_sleep(*args):