#14683 Python: Preserve positional heartbeat callback

This commit is contained in:
Kristian Bendiksen committed 2026-09-07 18:58:05 +02:00
1 parent 35614d160e
commit 2e5a3a3d17
2 files changed
+15 -4

No files matched your search

+4 -4
View File
@@ -418,8 +418,8 @@ class Instance:
interval_sec: float = 5.0,
deadline_sec: float = 5.0,
failure_threshold: int = 3,
busy_warning_sec: float = 60.0,
on_failure: Optional[Callable[["RipsError"], None]] = None,
busy_warning_sec: float = 60.0,
) -> None:
"""Start a background thread that periodically pings ResInsight.
@@ -452,12 +452,12 @@ class Instance:
failure_threshold: Number of consecutive *connection* failures
required before the connection is declared lost.
Must be >= 1.
busy_warning_sec: Log a warning when the server has been unable
to answer pings for this many seconds in a row. The pending
call is still allowed to run to completion.
on_failure: Optional callback invoked once when the
heartbeat detects a lost connection. Receives a
:class:`RipsError`.
busy_warning_sec: Log a warning when the server has been unable
to answer pings for this many seconds in a row. The pending
call is still allowed to run to completion.
"""
if failure_threshold < 1:
raise RipsError("failure_threshold must be >= 1")
@@ -160,6 +160,17 @@ def test_heartbeat_detects_dead_server():
instance.check_alive()
def test_heartbeat_preserves_positional_on_failure_argument():
instance = _FakeInstance(grpc.StatusCode.UNAVAILABLE)
failures = []
instance.start_heartbeat(0.02, 0.02, 1, failures.append)
instance._heartbeat_thread.join(timeout=0.5)
instance.stop_heartbeat()
assert len(failures) == 1
def test_heartbeat_reports_exited_process_with_diagnostic():
"""When the launched process has exited, say so explicitly instead of
surfacing a bare 'Channel closed!'."""