(
retry,
response,
expected_total=None,
expected_backoff=None,
expected_retry_backoff=None,
expect_retry_error=False,
has_reset=False,
)
| 59 | is_primary = expected_rate_limit_error == PrimaryRateLimitMessage |
| 60 | |
| 61 | def test_increment( |
| 62 | retry, |
| 63 | response, |
| 64 | expected_total=None, |
| 65 | expected_backoff=None, |
| 66 | expected_retry_backoff=None, |
| 67 | expect_retry_error=False, |
| 68 | has_reset=False, |
| 69 | ): |
| 70 | # fmt: off |
| 71 | self.assertTrue( |
| 72 | expected_total is not None and expected_backoff is not None and not expect_retry_error or # noqa: W504 |
| 73 | expected_total is None and expected_backoff is None and expect_retry_error |
| 74 | ) |
| 75 | # fmt: on |
| 76 | |
| 77 | orig_retry = retry |
| 78 | with mock.patch.object(retry, "_GithubRetry__log") as log: |
| 79 | if expect_retry_error: |
| 80 | with self.assertRaises(urllib3.exceptions.MaxRetryError): |
| 81 | retry.increment("TEST", "URL", response) |
| 82 | retry = None |
| 83 | else: |
| 84 | retry = retry.increment("TEST", "URL", response) |
| 85 | |
| 86 | self.assertEqual(expected_total, retry.total) |
| 87 | self.assertEqual( |
| 88 | expected_backoff if expected_retry_backoff is None else expected_retry_backoff, |
| 89 | retry.get_backoff_time(), |
| 90 | ) |
| 91 | self.assertEqual(orig_retry.secondary_rate_wait, retry.secondary_rate_wait) |
| 92 | |
| 93 | # fmt: off |
| 94 | log.assert_has_calls( |
| 95 | [ |
| 96 | mock.call(20, "Request TEST URL failed with 403: None"), |
| 97 | mock.call(10, f"Response body indicates retry-able {'primary' if is_primary else 'secondary'} rate limit error: {expected_rate_limit_error}"), |
| 98 | ] + ([ |
| 99 | mock.call(10, "Reset occurs in 0:00:12 (1644768012 / 2022-02-13 16:00:12+00:00)") |
| 100 | ] if has_reset else []) + ([ |
| 101 | mock.call(10, f"Retry backoff of {expected_retry_backoff}s exceeds required rate limit backoff of {expected_backoff}s") |
| 102 | ] if expected_retry_backoff and expected_backoff > 0 else []) + ([ |
| 103 | mock.call(20, f"Setting next backoff to {expected_backoff if expected_retry_backoff is None else expected_retry_backoff}s") |
| 104 | ] if not expect_retry_error else []), |
| 105 | any_order=False, |
| 106 | ) |
| 107 | # fmt: on |
| 108 | return retry |
| 109 | |
| 110 | return test_increment |
| 111 |
nothing calls this directly
no test coverage detected