MCPcopy Index your code
hub / github.com/googleapis/google-api-python-client / test_retry

Method test_retry

tests/test_http.py:998–1032  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

996 self.assertEqual({"foo": "bar"}, response)
997
998 def test_retry(self):
999 num_retries = 6
1000 resp_seq = [({"status": "500"}, "")] * (num_retries - 4)
1001 resp_seq.append(({"status": "403"}, RATE_LIMIT_EXCEEDED_RESPONSE))
1002 resp_seq.append(
1003 ({"status": "403"}, USER_RATE_LIMIT_EXCEEDED_RESPONSE_NO_STATUS)
1004 )
1005 resp_seq.append(
1006 ({"status": "403"}, USER_RATE_LIMIT_EXCEEDED_RESPONSE_WITH_STATUS)
1007 )
1008 resp_seq.append(({"status": "429"}, ""))
1009 resp_seq.append(({"status": "200"}, "{}"))
1010
1011 http = HttpMockSequence(resp_seq)
1012 model = JsonModel()
1013 uri = "https://www.googleapis.com/someapi/v1/collection/?foo=bar"
1014 method = "POST"
1015 request = HttpRequest(
1016 http,
1017 model.response,
1018 uri,
1019 method=method,
1020 body="{}",
1021 headers={"content-type": "application/json"},
1022 )
1023
1024 sleeptimes = []
1025 request._sleep = lambda x: sleeptimes.append(x)
1026 request._rand = lambda: 10
1027
1028 request.execute(num_retries=num_retries)
1029
1030 self.assertEqual(num_retries, len(sleeptimes))
1031 for retry_num in range(num_retries):
1032 self.assertEqual(10 * 2 ** (retry_num + 1), sleeptimes[retry_num])
1033
1034 def test_no_retry_succeeds(self):
1035 num_retries = 5

Callers

nothing calls this directly

Calls 4

executeMethod · 0.95
HttpMockSequenceClass · 0.90
JsonModelClass · 0.90
HttpRequestClass · 0.90

Tested by

no test coverage detected