mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
[linkcheck] Allow integer for linkcheck_rate_limit_timeout (#12470)
Eliminate type-related warnings when users configure a valid integer value for the `linkcheck_rate_limit_timeout` config setting. Co-authored-by: Chris Sewell <chrisj_sewell@hotmail.com>
This commit is contained in:
@@ -58,6 +58,9 @@ Bugs fixed
|
||||
Patch by Bénédikt Tran.
|
||||
* #12220: Fix loading custom template translations for ``en`` locale.
|
||||
Patch by Nicolas Peugnet.
|
||||
* #12459: Add valid-type arguments to the ``linkcheck_rate_limit_timeout``
|
||||
configuration setting.
|
||||
Patch by James Addison.
|
||||
|
||||
Improvements
|
||||
------------
|
||||
|
||||
@@ -2950,8 +2950,8 @@ Options for the linkcheck builder
|
||||
|
||||
Otherwise, ``linkcheck`` waits for a minute before to retry and keeps
|
||||
doubling the wait time between attempts until it succeeds or exceeds the
|
||||
``linkcheck_rate_limit_timeout``. By default, the timeout is 300 seconds
|
||||
and custom timeouts should be given in seconds.
|
||||
``linkcheck_rate_limit_timeout``. By default, the timeout is 300 seconds.
|
||||
Custom timeouts should be given as a number of seconds.
|
||||
|
||||
.. _Retry-After: https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.3
|
||||
|
||||
|
||||
@@ -708,7 +708,7 @@ def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
# commonly used for dynamic pages
|
||||
app.add_config_value('linkcheck_anchors_ignore', ['^!'], '')
|
||||
app.add_config_value('linkcheck_anchors_ignore_for_url', (), '', (tuple, list))
|
||||
app.add_config_value('linkcheck_rate_limit_timeout', 300.0, '')
|
||||
app.add_config_value('linkcheck_rate_limit_timeout', 300.0, '', (int, float))
|
||||
app.add_config_value('linkcheck_allow_unauthorized', True, '')
|
||||
app.add_config_value('linkcheck_report_timeouts_as_broken', True, '', bool)
|
||||
|
||||
|
||||
@@ -936,21 +936,23 @@ def test_limit_rate_doubles_previous_wait_time(app: Sphinx) -> None:
|
||||
assert next_check == 120.0
|
||||
|
||||
|
||||
@pytest.mark.sphinx(confoverrides={'linkcheck_rate_limit_timeout': 90.0})
|
||||
def test_limit_rate_clips_wait_time_to_max_time(app: Sphinx) -> None:
|
||||
@pytest.mark.sphinx(confoverrides={'linkcheck_rate_limit_timeout': 90})
|
||||
def test_limit_rate_clips_wait_time_to_max_time(app: Sphinx, warning: StringIO) -> None:
|
||||
rate_limits = {"localhost": RateLimit(60.0, 0.0)}
|
||||
worker = HyperlinkAvailabilityCheckWorker(app.config, Queue(), Queue(), rate_limits)
|
||||
with mock.patch('time.time', return_value=0.0):
|
||||
next_check = worker.limit_rate(FakeResponse.url, FakeResponse.headers.get("Retry-After"))
|
||||
assert next_check == 90.0
|
||||
assert warning.getvalue() == ''
|
||||
|
||||
|
||||
@pytest.mark.sphinx(confoverrides={'linkcheck_rate_limit_timeout': 90.0})
|
||||
def test_limit_rate_bails_out_after_waiting_max_time(app: Sphinx) -> None:
|
||||
def test_limit_rate_bails_out_after_waiting_max_time(app: Sphinx, warning: StringIO) -> None:
|
||||
rate_limits = {"localhost": RateLimit(90.0, 0.0)}
|
||||
worker = HyperlinkAvailabilityCheckWorker(app.config, Queue(), Queue(), rate_limits)
|
||||
next_check = worker.limit_rate(FakeResponse.url, FakeResponse.headers.get("Retry-After"))
|
||||
assert next_check is None
|
||||
assert warning.getvalue() == ''
|
||||
|
||||
|
||||
@mock.patch('sphinx.util.requests.requests.Session.get_adapter')
|
||||
|
||||
Reference in New Issue
Block a user