Creates a task that spawns a child, and then calls `stop_fn`, which should kill either the task or the worker. The function then checks that both the task process and its child have been killed.
(hq_env: HqEnv, stop_fn: Callable[[subprocess.Popen], None], terminates_worker=True)
| 159 | |
| 160 | |
| 161 | def check_task_processes_exited(hq_env: HqEnv, stop_fn: Callable[[subprocess.Popen], None], terminates_worker=True): |
| 162 | """ |
| 163 | Creates a task that spawns a child, and then calls `stop_fn`, which should kill either the task |
| 164 | or the worker. The function then checks that both the task process and its child have been killed. |
| 165 | """ |
| 166 | hq_env.start_server() |
| 167 | worker_process = hq_env.start_worker() |
| 168 | |
| 169 | hq_env.command( |
| 170 | [ |
| 171 | "submit", |
| 172 | "--", |
| 173 | *python( |
| 174 | """ |
| 175 | import os |
| 176 | import sys |
| 177 | import time |
| 178 | print(os.getpid(), flush=True) |
| 179 | pid = os.fork() |
| 180 | if pid > 0: |
| 181 | print(pid, flush=True) |
| 182 | time.sleep(3600) |
| 183 | """ |
| 184 | ), |
| 185 | ] |
| 186 | ) |
| 187 | wait_for_job_state(hq_env, 1, "RUNNING") |
| 188 | wait_until(lambda: len(read_file(default_task_output()).splitlines()) == 2) |
| 189 | pids = [int(pid) for pid in read_file(default_task_output()).splitlines()] |
| 190 | |
| 191 | stop_fn(worker_process) |
| 192 | |
| 193 | parent, child = pids |
| 194 | wait_for_pid_exit(parent) |
| 195 | wait_for_pid_exit(child) |
| 196 | if terminates_worker: |
| 197 | hq_env.check_process_exited(worker_process, None) |
no test coverage detected