Module: check_mk
Branch: master
Commit: 5b8fd23f8db69985870e9cd3346696bcc2f468d9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5b8fd23f8db699…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Jan 8 13:24:40 2019 +0100
Fix test_start_job() test
Change-Id: I459a434e713e902cad6b33d6764510d9cc9d0463
---
tests/unit/cmk/gui/test_background_job.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/tests/unit/cmk/gui/test_background_job.py
b/tests/unit/cmk/gui/test_background_job.py
index cd07c85..6470e66 100644
--- a/tests/unit/cmk/gui/test_background_job.py
+++ b/tests/unit/cmk/gui/test_background_job.py
@@ -1,5 +1,5 @@
import time
-import signal
+import multiprocessing
import sys
import pytest # type: ignore
from pathlib2 import Path
@@ -46,12 +46,14 @@ class DummyBackgroundJob(gui_background_job.GUIBackgroundJob):
kwargs["title"] = self.gui_title
kwargs["deletable"] = False
kwargs["stoppable"] = True
+ self.finish_hello_event = multiprocessing.Event()
super(DummyBackgroundJob, self).__init__(self.job_prefix, **kwargs)
def execute_hello(self, job_interface):
sys.stdout.write("Hallo :-)\n")
sys.stdout.flush()
+ self.finish_hello_event.wait()
def execute_endless(self):
sys.stdout.write("Hanging loop\n")
@@ -67,13 +69,14 @@ def test_start_job():
assert status["state"] == background_job.JobStatus.state_initialized
job.start()
- time.sleep(1)
assert job.is_running()
with pytest.raises(background_job.BackgroundJobAlreadyRunning):
job.start()
assert job.is_running()
+ job.finish_hello_event.set()
+
testlib.wait_until(
lambda: job.get_status()["state"] not in [
background_job.JobStatus.state_initialized, background_job.JobStatus.state_running ],
timeout=5,