Skip to content

Commit d43d102

Browse files
committed
fix(build): write the first maintained heartbeat when the hold is taken
A grace just over the 60s interval could otherwise expire a running build, because its first beat landed one interval plus a connect after its pauses.
1 parent f6c4ce0 commit d43d102

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎src/sqlbuild/executor/maintained_pauses/classes/maintained_heartbeat.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ def stop(self) -> None:
3838
self._thread.join()
3939

4040
def _beat(self) -> None:
41-
"""Reconnect after a failed beat; the grace, not one beat, decides when a hold expires."""
41+
"""Beat at once, then every interval, so no gap exceeds one interval plus a write."""
4242

4343
connection: Any = None
4444
sequence: int = 0
45-
while not self._stopped.wait(self._interval_seconds):
45+
stopped: bool = False
46+
while not stopped:
4647
sequence += 1
4748
try:
4849
if connection is None:
@@ -51,6 +52,7 @@ def _beat(self) -> None:
5152
except Exception as error:
5253
self.failure = error
5354
connection = self._closed(connection=connection)
55+
stopped = self._stopped.wait(self._interval_seconds)
5456
_ = self._closed(connection=connection)
5557

5658
def _closed(self, *, connection: Any) -> None:

‎tests/integration/src/sqlbuild/executor/maintained_pauses/test_maintained_pause_lease.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
hold_maintained_models,
2323
)
2424
from tests.integration.src.sqlbuild.executor.maintained_pauses._test_types import (
25+
ConcurrentHoldTestCase,
2526
FirstBuildTestCase,
2627
HeartbeatTestCase,
2728
HoldRefusalTestCase,
2829
HoldTakeoverTestCase,
2930
LifecycleLineTestCase,
3031
PauseLeaseTestCase,
31-
ConcurrentHoldTestCase,
3232
TakenOverReleaseTestCase,
3333
)
3434
from tests.integration.src.sqlbuild.executor.maintained_pauses.helpers import (
@@ -410,6 +410,12 @@ def test_given_live_hold_when_building_then_stops_before_any_change(
410410
wait_seconds=0.4,
411411
expected_min_beats=2,
412412
),
413+
HeartbeatTestCase(
414+
description="a hold beats as soon as it is taken, not one interval later",
415+
heartbeat_seconds=30.0,
416+
wait_seconds=0.3,
417+
expected_min_beats=1,
418+
),
413419
],
414420
ids=lambda case: case.description,
415421
)

0 commit comments

Comments
 (0)