From 22a6422731eebdec508afd6dcf0b0c1c21e67551 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Thu, 19 May 2022 17:17:01 +0200 Subject: [PATCH] Fix output of test_lowlevel tests in case of timeout 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: : 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 --- tests/testserver/server.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testserver/server.py b/tests/testserver/server.py index 6ca3a91716..5936abdf8b 100644 --- a/tests/testserver/server.py +++ b/tests/testserver/server.py @@ -115,7 +115,8 @@ def _accept_connection(self): def __enter__(self): self.start() - self.ready_event.wait(self.WAIT_EVENT_TIMEOUT) + if not self.ready_event.wait(self.WAIT_EVENT_TIMEOUT): + raise RuntimeError("Timeout waiting for server to be ready.") return self.host, self.port def __exit__(self, exc_type, exc_value, traceback):