def monitor_fixture(): from core.components.runtime_info import RuntimeInfo RuntimeInfo._refresh_system_info = types.MethodType( _refresh_info_hook, RuntimeInfo) helper.reset_db() Communicator() Logger() ForkProxy() module_proc = modules.Process(modules.Monitor) module_proc.start() fork_proxy_proc = multiprocessing.Process(target=_fork_proxy) fork_proxy_proc.start() yield {"set_system_info": _set_system_info} root_proc = psutil.Process(module_proc.pid) fork_proc = psutil.Process(fork_proxy_proc.pid) procs = root_proc.children(recursive=True) procs.append(fork_proc) procs.append(root_proc) try: for p in procs: p.terminate() p.wait(2) except Exception: raise Exception("Module process may not be killed success!") module_proc.join(3) fork_proxy_proc.join(3) helper.reset_db() Communicator.reset()
def test_launcher(): proc = multiprocessing.Process(target=Launcher().launch) proc.start() time.sleep(2) module_procs = psutil.Process(proc.pid).children(recursive=True) assert len(module_procs) > 2 proc.terminate() proc.join(5) if proc.is_alive(): raise Exception( "launcher process with pid {} may not be killed success!") time.sleep(Config().get_config("monitor.schedule_interval") * 2) for child in module_procs: try: child.wait(5) except psutil.TimeoutExpired: assert False Communicator.reset()
def preprocessor_fixture(): helper.reset_db() Communicator() Logger() module_proc = modules.Process(modules.Preprocessor) module_proc.start() yield module_proc root_proc = psutil.Process(module_proc.pid) procs = root_proc.children(recursive=True) try: root_proc.terminate() root_proc.wait(10) module_proc.join(5) for p in procs: p.terminate() p.wait(10) except psutil.TimeoutExpired: raise Exception("Module process may not be killed success!") helper.reset_db() Communicator.reset()