You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2022/05/10 21:38:59 UTC
[libcloud] 01/02: test/test_http.py: stop HTTP server (thread) properly
This is an automated email from the ASF dual-hosted git repository.
tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git
commit 43b71091ebd159570302b695f0a244f4d0a7e497
Author: Olivier Gayot <ol...@canonical.com>
AuthorDate: Tue May 10 19:16:16 2022 +0200
test/test_http.py: stop HTTP server (thread) properly
The HttpLayerTestCase test class creates a HTTPServer instance and runs
it in a separate thread.
After running all the test-cases, we attempt to close the server and the
thread by killing the thread. Unfortunately, the code that does that is
unreachable because the tear-down member function is called tearDownCls
intead of tearDownClass.
Moreover, there is no threading.Thread.kill function. This was undetected
because the code was unreachable.
The proper way to clean things up is to:
1. Stop the HTTP server using HTTPServer.shutdown()
2. Join the thread using threading.Thread.join()
---
libcloud/test/test_http.py | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/libcloud/test/test_http.py b/libcloud/test/test_http.py
index b693f31c2..e9ac5bc19 100644
--- a/libcloud/test/test_http.py
+++ b/libcloud/test/test_http.py
@@ -116,8 +116,9 @@ class HttpLayerTestCase(unittest.TestCase):
cls.mock_server_thread.start()
@classmethod
- def tearDownCls(cls):
- cls.mock_server_thread.kill()
+ def tearDownClass(cls):
+ cls.mock_server.shutdown()
+ cls.mock_server_thread.join()
def test_prepared_request_empty_body_chunked_encoding_not_used(self):
connection = LibcloudConnection(host=self.listen_host, port=self.listen_port)