Fix output of test_lowlevel tests in case of timeout#6136
Merged
nateprewitt merged 1 commit intopsf:mainfrom Jun 8, 2022
Merged
Fix output of test_lowlevel tests in case of timeout#6136nateprewitt merged 1 commit intopsf:mainfrom
nateprewitt merged 1 commit intopsf:mainfrom
Conversation
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>
nateprewitt
approved these changes
Jun 8, 2022
Member
nateprewitt
left a comment
There was a problem hiding this comment.
Cool, thanks @ogayot! It look like we omitted this due to Python 2.7 support, but we're free to merge now.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello,
The tests in
test_lowlevel.pyuse thetestserver.server.Serverthread 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 thewithbody with an uninitialized value forport(i.e.,port = 0).Therefore, the tests would fail with:
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:
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.hostislocalhost):Thanks,
Olivier