Skip to content
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

Merged
merged 1 commit into from Oct 30, 2019
Merged

bpo-38614: Add timeout constants to test.support #16964

merged 1 commit into from Oct 30, 2019

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Oct 28, 2019

Add timeout constants to test.support:

  • LOOPBACK_TIMEOUT
  • INTERNET_TIMEOUT
  • SHORT_TIMEOUT
  • LONG_TIMEOUT

https://bugs.python.org/issue38614

@vstinner
Copy link
Member Author

Somehow related, in 2014, I tried to make time.sleep() calls configurable in tests: https://bugs.python.org/issue20910

@vstinner
Copy link
Member Author

@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.

Copy link
Member

@pablogsal pablogsal left a 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!

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
Copy link
Member

@pablogsal pablogsal Oct 30, 2019

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`

Copy link
Member

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,

run in different threads or even different processes.

The timeout should be long enough for connect(), recv() and send() methods
of socket.socket.
Copy link
Member

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?

Copy link
Member

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.

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,

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().
Copy link
Member

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.


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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
slower. It is not designed to measure a function performance.
It is not designed to measure a function performance.

.. 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# For slowest buildbot worker, increase SHORT_TIMEOUT and LONG_TIMEOUT
# For a slow buildbot worker, increase SHORT_TIMEOUT and LONG_TIMEOUT


# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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


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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

# 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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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,

@pablogsal
Copy link
Member

pablogsal commented Oct 30, 2019

I'm not sure about the documentation of SHORT_TIMEOUT vs LONG_TIMEOUT.

Hummmm, maybe:

.. data:: SHORT_TIMEOUT
   Timeout in seconds that can be used to detect when a test hangs. It can be used
   in the average buildbots and is preferable over :data:`LONG_TIMEOUT` as it makes
   smaller pauses producing smaller run times for the test suite.

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
Copy link
Member

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,

run in different threads or even different processes.

The timeout should be long enough for connect(), recv() and send() methods
of socket.socket.
Copy link
Member

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=()):
Copy link
Member

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?

Copy link
Member Author

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
@vstinner
Copy link
Member Author

@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.

@pablogsal
Copy link
Member

Does it sound better to you?

Much better indeed!

Copy link
Member

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

@vstinner vstinner merged commit 24c6258 into python:master Oct 30, 2019
@vstinner vstinner deleted the support_timeout branch October 30, 2019 11:41
jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this pull request Dec 5, 2019
Add timeout constants to test.support:

* LOOPBACK_TIMEOUT
* INTERNET_TIMEOUT
* SHORT_TIMEOUT
* LONG_TIMEOUT
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
Add timeout constants to test.support:

* LOOPBACK_TIMEOUT
* INTERNET_TIMEOUT
* SHORT_TIMEOUT
* LONG_TIMEOUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants