Skip to content

Commit f1d6f49

Browse files
committed
Added python based script test
Used sys._exit instead of exception raise to exit both scenarios Updated click echo to always have [simvue]
1 parent 7a16c3a commit f1d6f49

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

simvue/run.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def __exit__(
189189
if _error_msg:
190190
_error_msg = f":\n{_error_msg}"
191191
click.secho(
192-
"Simvue process executor terminated with non-zero exit status "
192+
"[simvue] Process executor terminated with non-zero exit status "
193193
f"{_non_zero}{_error_msg}",
194194
fg="red",
195195
bold=True,
@@ -294,7 +294,8 @@ def _heartbeat(
294294
self._dispatcher.purge()
295295
self._dispatcher.join()
296296
self.set_status("terminated")
297-
raise RuntimeError("Run was aborted")
297+
click.secho("[simvue] Run was aborted.", fg="red", bold=True)
298+
os._exit(1)
298299

299300
if self._simvue:
300301
self._simvue.send_heartbeat()
@@ -1232,7 +1233,7 @@ def save_file(
12321233

12331234
if not file_size:
12341235
click.secho(
1235-
"WARNING: saving zero-sized files not currently supported",
1236+
"[simvue] WARNING: saving zero-sized files not currently supported",
12361237
bold=True,
12371238
fg="yellow",
12381239
)
@@ -1420,7 +1421,7 @@ def close(self) -> bool:
14201421
if _error_msg:
14211422
_error_msg = f":\n{_error_msg}"
14221423
click.secho(
1423-
"Simvue process executor terminated with non-zero exit status "
1424+
"[simvue] Process executor terminated with non-zero exit status "
14241425
f"{_non_zero}{_error_msg}",
14251426
fg="red",
14261427
bold=True,

tests/refactor/test_run_class.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ def test_save_object(
461461

462462

463463
@pytest.mark.run
464-
def test_abort_on_alert(create_plain_run: typing.Tuple[sv_run.Run, dict]) -> None:
464+
def test_abort_on_alert_process(create_plain_run: typing.Tuple[sv_run.Run, dict]) -> None:
465465
run, _ = create_plain_run
466466
run.config(resources_metrics_interval=1)
467467
run._heartbeat_interval = 1
@@ -473,6 +473,26 @@ def test_abort_on_alert(create_plain_run: typing.Tuple[sv_run.Run, dict]) -> Non
473473
if not run._status == "terminated":
474474
run.kill_all_processes()
475475
raise AssertionError("Run was not terminated")
476+
477+
478+
@pytest.mark.run
479+
def test_abort_on_alert_python(create_plain_run: typing.Tuple[sv_run.Run, dict]) -> None:
480+
run, _ = create_plain_run
481+
run.config(resources_metrics_interval=1)
482+
run._heartbeat_interval = 1
483+
client = sv_cl.Client()
484+
i = 0
485+
486+
while True:
487+
time.sleep(1)
488+
if i == 4:
489+
client.abort_run(run._id, reason="testing abort")
490+
i += 1
491+
if i == 10:
492+
break
493+
494+
assert i == 4
495+
assert run._status == "terminated"
476496

477497

478498
@pytest.mark.run

0 commit comments

Comments
 (0)