From f3d0b5e11ade90550cc232d5665df1dbc2bfebc5 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Wed, 25 Nov 2026 22:39:58 -0500 Subject: [PATCH] Test: restart while the database is away still catches up once it answers (T2 order) Co-Authored-By: Claude Opus 5.5 --- tests/test_monitor.py | 18 ++++++++++++++++++ thor/monitor.py | 2 ++ 2 files changed, 20 insertions(+) diff --git a/tests/test_monitor.py b/tests/test_monitor.py index 22e32f0..79cd654 100644 --- a/tests/test_monitor.py +++ b/tests/test_monitor.py @@ -176,3 +176,21 @@ def test_stop_ends_run_forever(): m.settings.cycle_seconds = 1 m.stop() m.run_forever() # returns at once + + +def test_restart_while_db_away_still_catches_up_once_db_answers(): + """T2 order: the rack comes back, Thor starts before CT 149 does.""" + store = FakeStore() + m, clock = make(store) + m.cycle() + went_dark = clock.t + clock.advance(22 * 60) + store.down = True + m2, _ = make(store, clock=clock) + first = m2.cycle() + assert first.window == (clock.t - 120, clock.t) # nothing known yet + clock.advance(120) + store.down = False + second = m2.cycle() + # The stored end wins, so the whole time Thor was away is reviewed, not just the last cycle. + assert second.window == (went_dark, clock.t) and second.catching_up diff --git a/thor/monitor.py b/thor/monitor.py index db02d3a..d38f02a 100644 --- a/thor/monitor.py +++ b/thor/monitor.py @@ -121,6 +121,8 @@ class Monitor: except DatabaseError as e: logger.warning('Could not load previous state yet: %s', e) return + # The stored end is at or before anything this process reviewed while the database + # was away, so it wins: the next window then covers the whole time Thor was gone. if isinstance(end, (int, float)): self.last_good_end = float(end) for name, st in statuses.items():