From 179f18c142b17578a57d95baee42c4a5929001e8 Mon Sep 17 00:00:00 2001 From: yshepilov Date: Thu, 27 Jul 2023 22:27:03 +0200 Subject: [PATCH] #602 fixed a bug that fast scripts were notified about finish before start --- src/execution/execution_service.py | 4 ++-- src/tests/execution_service_test.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/execution/execution_service.py b/src/execution/execution_service.py index 4118a574..d439f1ec 100644 --- a/src/execution/execution_service.py +++ b/src/execution/execution_service.py @@ -62,10 +62,10 @@ def start_script(self, config, user: User): config=config) self._active_executor_ids.add(execution_id) - self._add_post_finish_handling(execution_id, executor, user) - self._fire_execution_started(execution_id, user) + self._add_post_finish_handling(execution_id, executor, user) + return execution_id def stop_script(self, execution_id, user): diff --git a/src/tests/execution_service_test.py b/src/tests/execution_service_test.py index cbda159e..17ae410d 100644 --- a/src/tests/execution_service_test.py +++ b/src/tests/execution_service_test.py @@ -236,6 +236,20 @@ def test_finish_listener_by_id(self): self.get_process(id1).stop() self.assertEqual(1, len(notifications)) + def test_start_finish_listener_order(self): + executor._process_creator = create_process_wrapper + + execution_service = self.create_execution_service() + + notifications = [] + + execution_service.add_finish_listener(lambda _, __: notifications.append('finished')) + execution_service.add_start_listener(lambda _, __: notifications.append('started')) + + self._start(execution_service) + + self.assertEqual(['started', 'finished'], notifications) + def _start(self, execution_service, user_id=DEFAULT_USER_ID): return _start(execution_service, user_id)