def test_report_with_failed_finish_message_argument(unused_tcp_port): host = "localhost" url = f"ws://{host}:{unused_tcp_port}" reporter = Event(evaluator_url=url) job1 = Job({"name": "job1", "stdout": "stdout", "stderr": "stderr"}, 0) lines = [] with _mock_ws_thread(host, unused_tcp_port, lines): reporter.report( Init([job1], 1, 19, ee_id="ee_id", real_id=0, step_id=0)) reporter.report(Running(job1, 100, 10)) reporter.report(Finish().with_error("massive_failure")) assert len(lines) == 1
def test_report_only_job_running_for_successful_run(unused_tcp_port): host = "localhost" url = f"ws://{host}:{unused_tcp_port}" reporter = Event(evaluator_url=url) job1 = Job({"name": "job1", "stdout": "stdout", "stderr": "stderr"}, 0) lines = [] with _mock_ws_thread(host, unused_tcp_port, lines): reporter.report( Init([job1], 1, 19, ee_id="ee_id", real_id=0, step_id=0)) reporter.report(Running(job1, 100, 10)) reporter.report(Finish()) assert len(lines) == 1
def test_report_with_successful_exit_message_argument(unused_tcp_port): host = "localhost" url = f"ws://{host}:{unused_tcp_port}" reporter = Event(evaluator_url=url) job1 = Job({"name": "job1", "stdout": "stdout", "stderr": "stderr"}, 0) lines = [] with _mock_ws_thread(host, unused_tcp_port, lines): reporter.report( Init([job1], 1, 19, ee_id="ee_id", real_id=0, step_id=0)) reporter.report(Exited(job1, 0)) reporter.report(Finish().with_error("failed")) assert len(lines) == 1 event = json.loads(lines[0]) assert event["type"] == _FM_JOB_SUCCESS
def test_report_with_running_message_argument(unused_tcp_port): host = "localhost" url = f"ws://{host}:{unused_tcp_port}" reporter = Event(evaluator_url=url) job1 = Job({"name": "job1", "stdout": "stdout", "stderr": "stderr"}, 0) lines = [] with _mock_ws_thread(host, unused_tcp_port, lines): reporter.report( Init([job1], 1, 19, ee_id="ee_id", real_id=0, step_id=0)) reporter.report(Running(job1, 100, 10)) reporter.report(Finish()) assert len(lines) == 1 event = json.loads(lines[0]) assert event["type"] == _FM_JOB_RUNNING assert event["data"]["max_memory_usage"] == 100 assert event["data"]["current_memory_usage"] == 10
def test_report_with_successful_start_message_argument(unused_tcp_port): host = "localhost" url = f"ws://{host}:{unused_tcp_port}" reporter = Event(evaluator_url=url) job1 = Job({"name": "job1", "stdout": "stdout", "stderr": "stderr"}, 0) lines = [] with _mock_ws_thread(host, unused_tcp_port, lines): reporter.report( Init([job1], 1, 19, ee_id="ee_id", real_id=0, step_id=0)) reporter.report(Start(job1)) reporter.report(Finish()) assert len(lines) == 1 event = json.loads(lines[0]) assert event["type"] == _FM_JOB_START assert event["source"] == "/ert/ee/ee_id/real/0/step/0/job/0" assert os.path.basename(event["data"]["stdout"]) == "stdout" assert os.path.basename(event["data"]["stderr"]) == "stderr"
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)
def test_report_with_failed_start_message_argument(unused_tcp_port): host = "localhost" url = f"ws://{host}:{unused_tcp_port}" reporter = Event(evaluator_url=url) job1 = Job({"name": "job1", "stdout": "stdout", "stderr": "stderr"}, 0) lines = [] with _mock_ws_thread(host, unused_tcp_port, lines): reporter.report( Init([job1], 1, 19, ee_id="ee_id", real_id=0, step_id=0)) msg = Start(job1).with_error("massive_failure") reporter.report(msg) reporter.report(Finish()) assert len(lines) == 2 event = json.loads(lines[1]) assert event["type"] == _FM_JOB_FAILURE assert event["data"]["error_msg"] == "massive_failure"