Skip to content

Commit

Permalink
Adjust event reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
xjules committed Jan 18, 2025
1 parent 1261e9a commit f2511fe
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions tests/ert/unit_tests/forward_model_runner/test_event_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def test_report_with_successful_start_message_argument(unused_tcp_port):
reporter.report(Start(fmstep1))
reporter.report(Finish())

assert len(mock_server.messages) == 1
event = event_from_json(mock_server.messages[0])
assert len(mock_server.messages) == 3
event = event_from_json(mock_server.messages[1])
assert type(event) is ForwardModelStepStart
assert event.ensemble == "ens_id"
assert event.real == "0"
Expand All @@ -70,8 +70,8 @@ def test_report_with_failed_start_message_argument(unused_tcp_port):
reporter.report(msg)
reporter.report(Finish())

assert len(mock_server.messages) == 2
event = event_from_json(mock_server.messages[1])
assert len(mock_server.messages) == 4 # 2 msgs + connect, disconnect
event = event_from_json(mock_server.messages[2])
assert type(event) is ForwardModelStepFailure
assert event.error_msg == "massive_failure"

Expand All @@ -89,8 +89,8 @@ async def test_report_with_successful_exit_message_argument(unused_tcp_port):
reporter.report(Exited(fmstep1, 0))
reporter.report(Finish().with_error("failed"))

assert len(mock_server.messages) == 1
event = event_from_json(mock_server.messages[0])
assert len(mock_server.messages) == 3
event = event_from_json(mock_server.messages[1])
assert type(event) is ForwardModelStepSuccess


Expand All @@ -107,8 +107,10 @@ def test_report_with_failed_exit_message_argument(unused_tcp_port):
reporter.report(Exited(fmstep1, 1).with_error("massive_failure"))
reporter.report(Finish())

assert len(mock_server.messages) == 1
event = event_from_json(mock_server.messages[0])
assert len(mock_server.messages) == 3
assert mock_server.messages[0] == "CONNECT"
assert mock_server.messages[2] == "DISCONNECT"
event = event_from_json(mock_server.messages[1])
assert type(event) is ForwardModelStepFailure
assert event.error_msg == "massive_failure"

Expand All @@ -126,8 +128,11 @@ def test_report_with_running_message_argument(unused_tcp_port):
reporter.report(Running(fmstep1, ProcessTreeStatus(max_rss=100, rss=10)))
reporter.report(Finish())

assert len(mock_server.messages) == 1
event = event_from_json(mock_server.messages[0])
assert len(mock_server.messages) == 3

assert mock_server.messages[0] == "CONNECT"
assert mock_server.messages[2] == "DISCONNECT"
event = event_from_json(mock_server.messages[1])
assert type(event) is ForwardModelStepRunning
assert event.max_memory_usage == 100
assert event.current_memory_usage == 10
Expand All @@ -146,7 +151,7 @@ def test_report_only_job_running_for_successful_run(unused_tcp_port):
reporter.report(Running(fmstep1, ProcessTreeStatus(max_rss=100, rss=10)))
reporter.report(Finish())

assert len(mock_server.messages) == 1
assert len(mock_server.messages) == 3


def test_report_with_failed_finish_message_argument(unused_tcp_port):
Expand All @@ -162,7 +167,7 @@ def test_report_with_failed_finish_message_argument(unused_tcp_port):
reporter.report(Running(fmstep1, ProcessTreeStatus(max_rss=100, rss=10)))
reporter.report(Finish().with_error("massive_failure"))

assert len(mock_server.messages) == 1
assert len(mock_server.messages) == 3


def test_report_inconsistent_events(unused_tcp_port):
Expand Down Expand Up @@ -234,4 +239,6 @@ def test_report_with_reconnected_reporter_but_finished_jobs(unused_tcp_port):
if reporter._event_publisher_thread.is_alive():
reporter._event_publisher_thread.join()
assert reporter._done.is_set()
assert len(mock_server.messages) == 3, "expected 3 Job running messages"
assert len(mock_server.messages) == 5, (
"expected 3 Job running messages and CONNECT and DISCONNECT"
)

0 comments on commit f2511fe

Please sign in to comment.