|
| 1 | +import os |
| 2 | +import json |
1 | 3 | from ipsframework import Framework
|
2 | 4 |
|
3 | 5 |
|
@@ -84,6 +86,23 @@ def test_exception(tmpdir):
|
84 | 86 | assert "WORKER__exception_worker_2 ERROR Uncaught Exception in component method.\n" in lines
|
85 | 87 | assert "DRIVER__driver_1 ERROR Uncaught Exception in component method.\n" in lines
|
86 | 88 |
|
| 89 | + # check event log |
| 90 | + events = read_event_log(tmpdir) |
| 91 | + assert len(events) == 11 |
| 92 | + |
| 93 | + worker_call_end_event = events[8] |
| 94 | + |
| 95 | + assert worker_call_end_event["code"] == "DRIVER__driver" |
| 96 | + assert worker_call_end_event["eventtype"] == "IPS_CALL_END" |
| 97 | + assert not worker_call_end_event['ok'] |
| 98 | + assert worker_call_end_event["comment"] == "Error: \"Runtime error\" Target = test@exception_worker@2:step(0)" |
| 99 | + |
| 100 | + sim_end_event = events[10] |
| 101 | + assert sim_end_event["code"] == "Framework" |
| 102 | + assert sim_end_event["eventtype"] == "IPS_END" |
| 103 | + assert not sim_end_event['ok'] |
| 104 | + assert sim_end_event["comment"] == "Simulation Execution Error" |
| 105 | + |
87 | 106 |
|
88 | 107 | def test_bad_task(tmpdir):
|
89 | 108 | platform_file, config_file = write_basic_config_and_platform_files(tmpdir, worker='bad_task_worker')
|
@@ -111,6 +130,23 @@ def test_bad_task(tmpdir):
|
111 | 130 | assert "WORKER__bad_task_worker_2 ERROR Uncaught Exception in component method.\n" in lines
|
112 | 131 | assert "DRIVER__driver_1 ERROR Uncaught Exception in component method.\n" in lines
|
113 | 132 |
|
| 133 | + # check event log |
| 134 | + events = read_event_log(tmpdir) |
| 135 | + assert len(events) == 11 |
| 136 | + |
| 137 | + worker_call_end_event = events[8] |
| 138 | + |
| 139 | + assert worker_call_end_event["code"] == "DRIVER__driver" |
| 140 | + assert worker_call_end_event["eventtype"] == "IPS_CALL_END" |
| 141 | + assert not worker_call_end_event['ok'] |
| 142 | + assert worker_call_end_event["comment"] == "Error: \"task binary of wrong type, expected str but found int\" Target = test@bad_task_worker@2:step(0)" |
| 143 | + |
| 144 | + sim_end_event = events[10] |
| 145 | + assert sim_end_event["code"] == "Framework" |
| 146 | + assert sim_end_event["eventtype"] == "IPS_END" |
| 147 | + assert not sim_end_event['ok'] |
| 148 | + assert sim_end_event["comment"] == "Simulation Execution Error" |
| 149 | + |
114 | 150 |
|
115 | 151 | def test_bad_task_pool1(tmpdir):
|
116 | 152 | platform_file, config_file = write_basic_config_and_platform_files(tmpdir, worker='bad_task_pool_worker1')
|
@@ -192,3 +228,30 @@ def test_assign_protected_attribute(tmpdir):
|
192 | 228 |
|
193 | 229 | assert "WORKER__assign_protected_attribute_2 ERROR Uncaught Exception in component method.\n" in lines
|
194 | 230 | assert "DRIVER__driver_1 ERROR Uncaught Exception in component method.\n" in lines
|
| 231 | + |
| 232 | + # check event log |
| 233 | + events = read_event_log(tmpdir) |
| 234 | + assert len(events) == 11 |
| 235 | + |
| 236 | + worker_call_end_event = events[8] |
| 237 | + |
| 238 | + assert worker_call_end_event["code"] == "DRIVER__driver" |
| 239 | + assert worker_call_end_event["eventtype"] == "IPS_CALL_END" |
| 240 | + assert not worker_call_end_event['ok'] |
| 241 | + # python 3.10 includes the attribute name in the error message |
| 242 | + assert worker_call_end_event["comment"] in ("Error: \"can't set attribute\" Target = test@assign_protected_attribute@2:step(0)", |
| 243 | + "Error: \"can't set attribute 'args'\" Target = test@assign_protected_attribute@2:step(0)") |
| 244 | + |
| 245 | + sim_end_event = events[10] |
| 246 | + assert sim_end_event["code"] == "Framework" |
| 247 | + assert sim_end_event["eventtype"] == "IPS_END" |
| 248 | + assert not sim_end_event['ok'] |
| 249 | + assert sim_end_event["comment"] == "Simulation Execution Error" |
| 250 | + |
| 251 | + |
| 252 | +def read_event_log(tmpdir): |
| 253 | + sim_event_log_json = next(f for f in os.listdir(tmpdir.join("simulation_log")) if f.endswith(".json")) |
| 254 | + with open(str(tmpdir.join("simulation_log").join(sim_event_log_json)), 'r') as f: |
| 255 | + lines = f.readlines() |
| 256 | + |
| 257 | + return [json.loads(line) for line in lines] |
0 commit comments