From d659d9338bee5169727dfc8d19dd4d4ad0039885 Mon Sep 17 00:00:00 2001 From: Artsiom Mishuta Date: Tue, 14 May 2024 14:42:26 +0200 Subject: [PATCH] test/pylib: Introduce ManagerClient.test_finished_event introduce ManagerClient.test_finished_event to block access to REST client object from the test if ManagerClient.after_test method was called (test teardown started) --- test/pylib/manager_client.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/pylib/manager_client.py b/test/pylib/manager_client.py index 04c55b447d..ef6c4f0ae4 100644 --- a/test/pylib/manager_client.py +++ b/test/pylib/manager_client.py @@ -53,9 +53,17 @@ class ManagerClient(): self.api = ScyllaRESTAPIClient() self.metrics = ScyllaMetricsClient() self.thread_pool = ThreadPoolExecutor() + self.test_finished_event = asyncio.Event() @property def client(self): + if self.test_finished_event.is_set(): + raise Exception("ManagerClient.after_test method was called, client object is not accessible anymore") + # there are still can be issue when some task first obtains the client object, + # but usually, tests obtains the manager and uses the client as manager.client + # and there is an actual workaround for this case. + # It is better to fix the task rather than every time doing + # close all clients in after_test->create new during after_test->close again after after_test. _client = self.client_for_asyncio_loop.get(asyncio.get_running_loop(), None) if _client is None: _client = UnixRESTClient(self.sock_path) @@ -129,8 +137,10 @@ class ManagerClient(): async def after_test(self, test_case_name: str, success: bool) -> None: """Tell harness this test finished""" + self.test_finished_event.set() + _client = self.client_for_asyncio_loop.get(asyncio.get_running_loop()) logger.debug("after_test for %s (success: %s)", test_case_name, success) - cluster_str = await self.client.put_json(f"/cluster/after-test/{success}", + cluster_str = await _client.put_json(f"/cluster/after-test/{success}", response_type = "json") logger.info("Cluster after test %s: %s", test_case_name, cluster_str)