def test_no_json_jobs_json_file(self): path = os.path.realpath(os.curdir) jobs_file = os.path.join(path, "jobs.json") with open(jobs_file, "w") as f: f.write("not json") with self.assertRaises(OSError): main(["script.py", path])
def test_job_dispatch_kills_itself_after_unsuccessful_job(self): with patch("job_runner.cli.os") as mock_os, patch( "job_runner.cli.JobRunner") as mock_runner: mock_runner.return_value.run.return_value = [ Finish().with_error("overall bad run") ] mock_os.getpgid.return_value = 17 main(["script.py", "/foo/bar/baz"]) mock_os.killpg.assert_called_with(17, signal.SIGKILL)
def test_job_dispatch_kills_itself_after_unsuccessful_job(self): jobs_json = json.dumps({"ee_id": "_id_"}) with patch("job_runner.cli.os") as mock_os, patch( "job_runner.cli.open", new=mock_open(read_data=jobs_json)) as mock_file, patch( "job_runner.cli.JobRunner") as mock_runner: mock_runner.return_value.run.return_value = [ Init([], 0, 0), Finish().with_error("overall bad run"), ] mock_os.getpgid.return_value = 17 main(["script.py", "/foo/bar/baz"]) mock_os.killpg.assert_called_with(17, signal.SIGKILL)
def test_job_dispatch_kills_itself_after_unsuccessful_job(unused_tcp_port): host = "localhost" port = unused_tcp_port jobs_json = json.dumps({"ee_id": "_id_", "dispatch_url": f"ws://localhost:{port}"}) with patch("job_runner.cli.os") as mock_os, patch( "job_runner.cli.open", new=mock_open(read_data=jobs_json) ) as mock_file, patch("job_runner.cli.JobRunner") as mock_runner: mock_runner.return_value.run.return_value = [ Init([], 0, 0), Finish().with_error("overall bad run"), ] mock_os.getpgid.return_value = 17 with _mock_ws_thread(host, port, []): main(["script.py", "/foo/bar/baz"]) mock_os.killpg.assert_called_with(17, signal.SIGKILL)
#!/usr/bin/env python import os import signal import sys from job_runner.cli import main def sigterm_handler(_signo, _stack_frame): signal.signal(signal.SIGTERM, signal.SIG_DFL) os.kill(0, signal.SIGTERM) ################################################################# ################################################################# os.nice(19) if __name__ == "__main__": signal.signal(signal.SIGTERM, sigterm_handler) main(sys.argv)
def test_no_jobs_json_file(self): with self.assertRaises(IOError): main(["script.py", os.path.realpath(os.curdir)])