Skip to content

Commit 1109c58

Browse files
committed
Fixed abort data being in wrong request
Updated alert comparison to check for abort
1 parent 1d89c7c commit 1109c58

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

simvue/run.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,7 @@ def create_alert(
17331733
"source": source,
17341734
"alert": alert_definition,
17351735
"description": description,
1736+
"abort": trigger_abort,
17361737
}
17371738

17381739
# Check if the alert already exists
@@ -1753,6 +1754,7 @@ def create_alert(
17531754

17541755
if not alert_id:
17551756
try:
1757+
logger.debug(f"Creating new alert with definition: {alert}")
17561758
response = self._simvue.add_alert(alert)
17571759
except RuntimeError as e:
17581760
self._error(f"{e.args[0]}")
@@ -1766,7 +1768,8 @@ def create_alert(
17661768

17671769
if alert_id:
17681770
# TODO: What if we keep existing alerts/add a new one later?
1769-
data = {"id": self._id, "alerts": [alert_id], "abort": trigger_abort}
1771+
data = {"id": self._id, "alerts": [alert_id]}
1772+
logger.debug(f"Updating run with info: {data}")
17701773

17711774
try:
17721775
self._simvue.update(data)

simvue/utilities.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,9 @@ def validate_timestamp(timestamp):
332332

333333
def compare_alerts(first, second):
334334
""" """
335-
for key in ("name", "description", "source", "frequency", "notification"):
335+
for key in ("name", "description", "source", "frequency", "notification", "abort"):
336336
if key in first and key in second:
337-
if not first[key]:
337+
if first[key] is None:
338338
continue
339339

340340
if first[key] != second[key]:
@@ -343,7 +343,7 @@ def compare_alerts(first, second):
343343
if "alerts" in first and "alerts" in second:
344344
for key in ("rule", "window", "metric", "threshold", "range_low", "range_high"):
345345
if key in first["alerts"] and key in second["alerts"]:
346-
if not first[key]:
346+
if first[key] is None:
347347
continue
348348

349349
if first["alerts"][key] != second["alerts"]["key"]:

tests/refactor/test_run_class.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,23 @@ def testing_exit(status: int) -> None:
487487
run.kill_all_processes()
488488
raise AssertionError("Run was not terminated")
489489

490+
@pytest.mark.run
491+
def test_abort_on_alert_raise(create_plain_run: typing.Tuple[sv_run.Run, dict], mocker: pytest_mock.MockerFixture) -> None:
492+
def testing_exit(status: int) -> None:
493+
raise SystemExit(status)
494+
mocker.patch("os._exit", testing_exit)
495+
run, _ = create_plain_run
496+
run.config(resources_metrics_interval=1)
497+
run._heartbeat_interval = 1
498+
run._testing = True
499+
alert_id = run.create_alert("abort_test", source="user", trigger_abort=True)
500+
run.add_process(identifier="forever_long", executable="bash", c="sleep 10")
501+
time.sleep(2)
502+
run.log_alert(alert_id, "critical")
503+
time.sleep(4)
504+
if not run._status == "terminated":
505+
run.kill_all_processes()
506+
raise AssertionError("Run was not terminated")
490507

491508
@pytest.mark.run
492509
def test_abort_on_alert_python(create_plain_run: typing.Tuple[sv_run.Run, dict], mocker: pytest_mock.MockerFixture) -> None:

0 commit comments

Comments
 (0)