New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-38614: Add timeout constants to test.support #16964
Conversation
Somehow related, in 2014, I tried to make time.sleep() calls configurable in tests: https://bugs.python.org/issue20910 |
@pablogsal: Would you mind to review this PR? I'm not sure about the documentation of SHORT_TIMEOUT vs LONG_TIMEOUT. LONG_TIMEOUT is 10 times larger than SHORT_TIMEOUT. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this @vstinner ! 🎉
I left some comments regarding style and minor nits!
Doc/library/test.rst
Outdated
prevent test failure: it takes an account that the client and the server can | ||
run in different threads or even different processes. | ||
|
||
The timeout should be long enough for connect(), recv() and send() methods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: should we add markup links to connect()
, recv()
...?
Basically `connect` -> :meth:`socket.socket.connect`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or perhaps :meth:~socket.socket.connect
to avoid showing the fully-qualified name,
Doc/library/test.rst
Outdated
run in different threads or even different processes. | ||
|
||
The timeout should be long enough for connect(), recv() and send() methods | ||
of socket.socket. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Markup link to socket.socket
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps not needed if the methods are linked.
Doc/library/test.rst
Outdated
is short enough to prevent a test to wait for too long if the Internet | ||
request is blocked for whatever reason. | ||
|
||
Usually, a timeout using INTERNET_TIMEOUT should not mark a test a failed, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually, a timeout using INTERNET_TIMEOUT should not mark a test a failed, | |
Usually, a timeout using INTERNET_TIMEOUT should not mark a test as failed, |
Doc/library/test.rst
Outdated
request is blocked for whatever reason. | ||
|
||
Usually, a timeout using INTERNET_TIMEOUT should not mark a test a failed, | ||
but skip the test instead: see transient_internet(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: link to transient_internet
if it makes sense.
Doc/library/test.rst
Outdated
|
||
Timeout in seconds that can be used to detect when a test hangs. It is long | ||
enough to reduce the risk of test failure on the slowest Python buildbot | ||
slower. It is not designed to measure a function performance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slower. It is not designed to measure a function performance. | |
It is not designed to measure a function performance. |
Doc/library/test.rst
Outdated
.. data:: LONG_TIMEOUT | ||
|
||
Timeout in seconds that can be used to detect when a test hangs. It is long | ||
enough to reduce the risk of test failure on the slowest Python buildbot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enough to reduce the risk of test failure on the slowest Python buildbot | |
enough to reduce the risk of test failure on the slowest Python buildbot. |
Lib/test/libregrtest/setup.py
Outdated
@@ -81,6 +81,17 @@ def _test_audit_hook(name, args): | |||
|
|||
setup_unraisable_hook() | |||
|
|||
if ns.timeout is not None: | |||
# For slowest buildbot worker, increase SHORT_TIMEOUT and LONG_TIMEOUT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# For slowest buildbot worker, increase SHORT_TIMEOUT and LONG_TIMEOUT | |
# For a slow buildbot worker, increase SHORT_TIMEOUT and LONG_TIMEOUT |
Lib/test/support/__init__.py
Outdated
|
||
# Timeout in seconds for tests using a network server listening on the network | ||
# local loopback interface like 127.0.0.1 (IPv4) or ::1 (IPv6). The timeout is | ||
# long enough to prevent test failure: it takes an account that the client and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# long enough to prevent test failure: it takes an account that the client and | |
# long enough to prevent test failure: it takes into account that the client and |
Doc/library/test.rst
Outdated
|
||
Timeout in seconds for tests using a network server listening on the network | ||
local loopback interface like ``127.0.0.1``). The timeout is long enough to | ||
prevent test failure: it takes an account that the client and the server can |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prevent test failure: it takes an account that the client and the server can | |
prevent test failure: it takes into account that the client and the server can |
Lib/test/support/__init__.py
Outdated
# short enough to prevent a test to wait for too long if the Internet request | ||
# is blocked for whatever reason. | ||
# | ||
# Usually, a timeout using INTERNET_TIMEOUT should not mark a test a failed, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Usually, a timeout using INTERNET_TIMEOUT should not mark a test a failed, | |
# Usually, a timeout using INTERNET_TIMEOUT should not mark a test as failed, |
Hummmm, maybe:
|
Doc/library/test.rst
Outdated
prevent test failure: it takes an account that the client and the server can | ||
run in different threads or even different processes. | ||
|
||
The timeout should be long enough for connect(), recv() and send() methods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or perhaps :meth:~socket.socket.connect
to avoid showing the fully-qualified name,
Doc/library/test.rst
Outdated
run in different threads or even different processes. | ||
|
||
The timeout should be long enough for connect(), recv() and send() methods | ||
of socket.socket. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps not needed if the methods are linked.
@@ -1542,9 +1585,12 @@ def get_socket_conn_refused_errs(): | |||
|
|||
|
|||
@contextlib.contextmanager | |||
def transient_internet(resource_name, *, timeout=30.0, errnos=()): | |||
def transient_internet(resource_name, *, timeout=_NOT_SET, errnos=()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this special value rather than None
, as in the other cases? Is it to support None
as an actual timeout value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one test_socket test which requires timeout=None.
Add timeout constants to test.support: * LOOPBACK_TIMEOUT * INTERNET_TIMEOUT * SHORT_TIMEOUT * LONG_TIMEOUT
@pablogsal: I rephased the documentation to better distinguish SHORT and LONG timeout. Does it sound better to you? I took your review in account. I checked manually the HTML documentation to ensure that it's rendered properly ;-) I revert changes to use new timeouts, except test_socket and _test_multiprocessing to make this PR easier to review. I will write more PRs to use the new constants, I start to modify tons of tests, I prefer to have separated PRs to make them easier to review. |
Much better indeed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
Add timeout constants to test.support: * LOOPBACK_TIMEOUT * INTERNET_TIMEOUT * SHORT_TIMEOUT * LONG_TIMEOUT
Add timeout constants to test.support: * LOOPBACK_TIMEOUT * INTERNET_TIMEOUT * SHORT_TIMEOUT * LONG_TIMEOUT
Add timeout constants to test.support:
https://bugs.python.org/issue38614