|
1 | 1 | import pytest
|
| 2 | +import os |
2 | 3 | import pytest_mock
|
3 | 4 | import time
|
4 | 5 | import typing
|
@@ -512,28 +513,39 @@ def abort_callback(abort_run=trigger) -> None:
|
512 | 513 |
|
513 | 514 |
|
514 | 515 | @pytest.mark.run
|
515 |
| -def test_abort_on_alert_python(create_plain_run: typing.Tuple[sv_run.Run, dict], mocker: pytest_mock.MockerFixture) -> None: |
516 |
| - abort_set = threading.Event() |
517 |
| - def testing_exit(status: int) -> None: |
518 |
| - abort_set.set() |
519 |
| - raise SystemExit(status) |
520 |
| - mocker.patch("os._exit", testing_exit) |
521 |
| - run, _ = create_plain_run |
522 |
| - run.config(resources_metrics_interval=1) |
523 |
| - run._heartbeat_interval = 1 |
524 |
| - client = sv_cl.Client() |
525 |
| - i = 0 |
526 |
| - |
527 |
| - while True: |
528 |
| - time.sleep(1) |
529 |
| - if i == 4: |
530 |
| - client.abort_run(run._id, reason="testing abort") |
531 |
| - i += 1 |
532 |
| - if abort_set.is_set() or i > 9: |
533 |
| - break |
534 |
| - |
535 |
| - assert i < 7 |
536 |
| - assert run._status == "terminated" |
| 516 | +def test_abort_on_alert_python(mocker: pytest_mock.MockerFixture) -> None: |
| 517 | + with simvue.Run() as run: |
| 518 | + run.config(suppress_errors=False) |
| 519 | + run.init( |
| 520 | + name="test_abort_on_alert_python", |
| 521 | + tags=["simvue_client_unit_tests"], |
| 522 | + folder="/simvue_unit_testing", |
| 523 | + visibility="tenant" if os.environ.get("CI") else None, |
| 524 | + retention_period="1 hour", |
| 525 | + timeout=60, |
| 526 | + no_color=True |
| 527 | + ) |
| 528 | + |
| 529 | + abort_set = threading.Event() |
| 530 | + def testing_exit(status: int) -> None: |
| 531 | + abort_set.set() |
| 532 | + raise SystemExit(status) |
| 533 | + mocker.patch("os._exit", testing_exit) |
| 534 | + run.config(resources_metrics_interval=1) |
| 535 | + run._heartbeat_interval = 1 |
| 536 | + client = sv_cl.Client() |
| 537 | + i = 0 |
| 538 | + |
| 539 | + while True: |
| 540 | + time.sleep(1) |
| 541 | + if i == 4: |
| 542 | + client.abort_run(run._id, reason="testing abort") |
| 543 | + i += 1 |
| 544 | + if abort_set.is_set() or i > 9: |
| 545 | + break |
| 546 | + |
| 547 | + assert i < 7 |
| 548 | + assert run._status == "terminated" |
537 | 549 |
|
538 | 550 |
|
539 | 551 | @pytest.mark.run
|
|
0 commit comments