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

Fix output of test_lowlevel tests in case of timeout #6136

Merged
merged 1 commit into from
Jun 8, 2022

Conversation

ogayot
Copy link
Contributor

@ogayot ogayot commented May 19, 2022

Hello,

The tests in test_lowlevel.py use the testserver.server.Server thread object.

When using the object as a context manager, we wait until the server thread is ready with a timeout.

Unfortunately, if the timeout is reached, we would not propagate the error. Instead, we would return from the __enter__ method and access the with body with an uninitialized value for port (i.e., port = 0).

Therefore, the tests would fail with:

E           urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fc3a3e30a90>: Failed to establish a new connection: [Errno 111] Connection refused

/usr/lib/python3/dist-packages/urllib3/connection.py:181: NewConnectionError

Reading this error does not make it obvious that this is the result of a timeout.

Fixed by raising an error in case of timeout, which makes it more obvious:

        if not self.ready_event.wait(self.WAIT_EVENT_TIMEOUT):
>           raise RuntimeError("Timeout waiting for server to be ready.")
E           RuntimeError: Timeout waiting for server to be ready.

tests/testserver/server.py:119: RuntimeError

The reason why I had a timeout on my end was because my environment was not resolving "localhost" as it should have. Requests were going through the DNS and therefore ended-up hitting the timeout

The name resolution taking forever was happening during this instruction (where self.host is localhost):

sock.bind((self.host, self.port))

Thanks,
Olivier

The tests in test_lowlevel.py use the testserver.server.Server thread
object.

When using the object as a context manager, we wait until the server
thread is ready with a timeout.

Unfortunately, if the timeout is reached, we would not propagate the
error. Instead, we would return from the __enter__ method and access the
"with" body with an uninitialized value for port (i.e., port = 0).

Therefore, the tests fail with:

E           urllib3.exceptions.NewConnectionError:
<urllib3.connection.HTTPConnection object at 0x7f068405aec0>: Failed to
establish a new connection: [Errno 111] Connection refused

Reading this error does not make it obvious that this is the result of a
timeout.

Fixed by raising an error in case of timeout.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
Copy link
Member

@nateprewitt nateprewitt left a comment

Choose a reason for hiding this comment

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

Cool, thanks @ogayot! It look like we omitted this due to Python 2.7 support, but we're free to merge now.

@nateprewitt nateprewitt merged commit 3af2f45 into psf:main Jun 8, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants