swh_scheduler = <swh.scheduler.backend.SchedulerBackend object at 0x7f98ffa3e2b0>
caplog = <_pytest.logging.LogCaptureFixture object at 0x7f98ffa3e198>
requests_ratelimited = <requests_mock.mocker.Mocker object at 0x7f98ffa3e9e8>
monkeypatch_sleep_calls = [1, 1, 1, 1, 1, 1, ...], num_before_ratelimit = 5
ratelimit_reset = 123456
github_credentials = [{'password': 'token-legacy-0', 'username': 'swh-legacy0'}, {'password': 'token-legacy-1', 'username': 'swh-legacy1'},...n': 'token-0', 'username': 'swh0'}, {'token': 'token-1', 'username': 'swh1'}, {'token': 'token-2', 'username': 'swh2'}]
lister_credentials = {'github': {'github': [{'password': 'token-legacy-0', 'username': 'swh-legacy0'}, {'password': 'token-legacy-1', 'user...: 'token-0', 'username': 'swh0'}, {'token': 'token-1', 'username': 'swh1'}, {'token': 'token-2', 'username': 'swh2'}]}}
@pytest.mark.parametrize(
# Do 5 successful requests, return 6 ratelimits (to exhaust the credentials) with a
# set value for X-Ratelimit-Reset, then resume listing successfully.
"num_before_ratelimit, num_ratelimit, ratelimit_reset",
[(5, 6, 123456)],
)
def test_ratelimit_reset_sleep(
swh_scheduler,
caplog,
requests_ratelimited,
monkeypatch_sleep_calls,
num_before_ratelimit,
ratelimit_reset,
github_credentials,
lister_credentials,
):
"""Check that the lister properly handles rate-limiting when providing it with
authentication tokens"""
caplog.set_level(logging.DEBUG, "swh.lister.github.lister")
lister = GitHubLister(scheduler=swh_scheduler, credentials=lister_credentials)
res = lister.run()
assert res == ListerStats(pages=NUM_PAGES, origins=ORIGIN_COUNT)
# We sleep 1 second every time we change credentials, then we sleep until
# ratelimit_reset + 1
expected_sleep_calls = len(github_credentials) * [1] + [ratelimit_reset + 1]
assert monkeypatch_sleep_calls == expected_sleep_calls
found_exhaustion_message = False
for record in caplog.records:
if record.levelname == "INFO":
if "Rate limits exhausted for all tokens" in record.message:
found_exhaustion_message = True
break
> assert found_exhaustion_message
E assert False
.tox/py3/lib/python3.7/site-packages/swh/lister/github/tests/test_lister.py:418: AssertionError
TEST RESULT
TEST RESULT
- Run At
- Apr 25 2022, 3:49 PM