Skip to content

Commit 0620196

Browse files
committed
Fix retention in test and set interval for resources to be shorter
1 parent a1d3337 commit 0620196

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

simvue/run.py

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def __init__(self, mode: typing.Literal["online", "offline"] = "online") -> None
101101
self._simvue: typing.Optional[SimvueBaseClass] = None
102102
self._pid: typing.Optional[int] = 0
103103
self._shutdown_event: typing.Optional[threading.Event] = None
104+
self._configuration_lock = threading.Lock()
104105
self._heartbeat_termination_trigger: typing.Optional[threading.Event] = None
105106
self._storage_id: typing.Optional[str] = None
106107
self._heartbeat_thread: typing.Optional[threading.Thread] = None
@@ -226,18 +227,19 @@ def _heartbeat(
226227
while not heartbeat_trigger.is_set():
227228
time.sleep(0.1)
228229

229-
if (
230-
self._resources_metrics_interval
231-
and (res_time := time.time()) - last_res_metric_call
232-
> self._resources_metrics_interval
233-
):
234-
# Set join on fail to false as if an error is thrown
235-
# join would be called on this thread and a thread cannot
236-
# join itself!
237-
self._add_metrics_to_dispatch(
238-
self._get_sysinfo(), join_on_fail=False
239-
)
240-
last_res_metric_call = res_time
230+
with self._configuration_lock:
231+
if (
232+
self._resources_metrics_interval
233+
and (res_time := time.time()) - last_res_metric_call
234+
> self._resources_metrics_interval
235+
):
236+
# Set join on fail to false as if an error is thrown
237+
# join would be called on this thread and a thread cannot
238+
# join itself!
239+
self._add_metrics_to_dispatch(
240+
self._get_sysinfo(), join_on_fail=False
241+
)
242+
last_res_metric_call = res_time
241243

242244
if time.time() - last_heartbeat < HEARTBEAT_INTERVAL:
243245
continue
@@ -797,27 +799,28 @@ def config(
797799
_description_
798800
"""
799801

800-
if suppress_errors is not None:
801-
self._suppress_errors = suppress_errors
802+
with self._configuration_lock:
803+
if suppress_errors is not None:
804+
self._suppress_errors = suppress_errors
802805

803-
if queue_blocking is not None:
804-
self._queue_blocking = queue_blocking
806+
if queue_blocking is not None:
807+
self._queue_blocking = queue_blocking
805808

806-
if resources_metrics_interval and disable_resources_metrics:
807-
self._error(
808-
"Setting of resource metric interval and disabling resource metrics is ambiguous"
809-
)
810-
return False
809+
if resources_metrics_interval and disable_resources_metrics:
810+
self._error(
811+
"Setting of resource metric interval and disabling resource metrics is ambiguous"
812+
)
813+
return False
811814

812-
if disable_resources_metrics:
813-
self._pid = None
814-
self._resources_metrics_interval = None
815+
if disable_resources_metrics:
816+
self._pid = None
817+
self._resources_metrics_interval = None
815818

816-
if resources_metrics_interval:
817-
self._resources_metrics_interval = resources_metrics_interval
819+
if resources_metrics_interval:
820+
self._resources_metrics_interval = resources_metrics_interval
818821

819-
if storage_id:
820-
self._storage_id = storage_id
822+
if storage_id:
823+
self._storage_id = storage_id
821824

822825
return True
823826

tests/refactor/test_run_class.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ def test_log_metrics(
3838
name=f"test_run_{str(uuid.uuid4()).split('-', 1)[0]}",
3939
tags=["simvue_client_unit_tests"],
4040
folder="/simvue_unit_testing",
41-
ttl=60 * 60,
42-
visibility=visibility
41+
retention_period="1 hour",
42+
visibility=visibility,
43+
resources_metrics_interval=1
4344
)
4445
return
4546

@@ -48,6 +49,7 @@ def test_log_metrics(
4849
tags=["simvue_client_unit_tests"],
4950
folder="/simvue_unit_testing",
5051
visibility=visibility,
52+
resources_metrics_interval=1,
5153
retention_period="1 hour",
5254
)
5355

0 commit comments

Comments
 (0)