diff --git a/test/int/procstar/ignore-term b/test/int/procstar/ignore-term index 71c3fd6a..3502cfc5 100755 --- a/test/int/procstar/ignore-term +++ b/test/int/procstar/ignore-term @@ -3,6 +3,7 @@ from argparse import ArgumentParser import signal import time +import sys parser = ArgumentParser() parser.add_argument("sleep", metavar="SECS", type=float) @@ -10,11 +11,11 @@ args = parser.parse_args() def sigterm(signum, frame): sig = signal.Signals(signum) - print(f"ignoring {sig.name}") + print(f"ignoring {sig.name}", file=sys.stderr) signal.signal(signal.Signals.SIGTERM, sigterm) -print(f"sleeping for {args.sleep} sec") +print(f"sleeping for {args.sleep} sec", file=sys.stderr) time.sleep(args.sleep) -print("done") +print("done", file=sys.stderr) diff --git a/test/int/procstar/test_stop.py b/test/int/procstar/test_stop.py index dea2010a..4917e65d 100644 --- a/test/int/procstar/test_stop.py +++ b/test/int/procstar/test_stop.py @@ -6,10 +6,16 @@ #------------------------------------------------------------------------------- -IGNORE_TERM_PATH = Path(__file__).parent / "ignore-term" +SLEEP_JOB = jso_to_job({ + "params": ["time"], + "program": { + "type": "procstar", + "argv": ["/usr/bin/sleep", "{{ time }}"], + } +}, "sleep") -JOB_ID = "ignore term" -JOB = jso_to_job({ +IGNORE_TERM_PATH = Path(__file__).parent / "ignore-term" +IGNORE_TERM_JOB = jso_to_job({ "params": ["time"], "program": { "type": "procstar", @@ -18,14 +24,36 @@ "grace_period": 2, }, } -}, JOB_ID) +}, "ignore term") + +def test_stop(): + svc = ApsisService() + dump_job(svc.jobs_dir, SLEEP_JOB) + with svc, svc.agent(): + # Schedule a 3 sec job but tell Apsis to stop it after 1 sec. + run_id = svc.client.schedule( + SLEEP_JOB.job_id, {"time": "3"}, + stop_time="+1s", + )["run_id"] + res = svc.wait_run(run_id) + + # The run was successfully stopped by Apsis, by sending it SIGTERM. + assert res["state"] == "success" + meta = res["meta"]["program"] + assert meta["status"]["signal"] == "SIGTERM" + assert meta["stop"]["signals"] == ["SIGTERM"] + assert meta["times"]["elapsed"] < 2 + def test_dont_stop(): svc = ApsisService() - dump_job(svc.jobs_dir, JOB) + dump_job(svc.jobs_dir, IGNORE_TERM_JOB) with svc, svc.agent(): # Schedule a 1 sec run but tell Apsis to stop it after 3 sec. - run_id = svc.client.schedule(JOB_ID, {"time": "1"}, stop_time="+3s")["run_id"] + run_id = svc.client.schedule( + IGNORE_TERM_JOB.job_id, {"time": "1"}, + stop_time="+3s" + )["run_id"] res = svc.wait_run(run_id) assert res["state"] == "success" @@ -37,12 +65,15 @@ def test_dont_stop(): def test_kill(): svc = ApsisService() - dump_job(svc.jobs_dir, JOB) + dump_job(svc.jobs_dir, IGNORE_TERM_JOB) with svc, svc.agent(): # Schedule a 5 sec run but tell Apsis to stop it after 1 sec. The # process ignores SIGTERM so Apsis will send SIGQUIT after the grace # period. - run_id = svc.client.schedule(JOB_ID, {"time": "5"}, stop_time="+1s")["run_id"] + run_id = svc.client.schedule( + IGNORE_TERM_JOB.job_id, {"time": "5"}, + stop_time="+1s" + )["run_id"] time.sleep(1.5) res = svc.client.get_run(run_id) @@ -57,4 +88,8 @@ def test_kill(): assert meta["stop"]["signals"] == ["SIGTERM", "SIGKILL"] assert meta["times"]["elapsed"] > 2.8 + output = svc.client.get_output(run_id, "output").decode() + assert "ignoring SIGTERM" in output + assert "done" not in output +