mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-08-23 03:18:15 +00:00
fix(display): consume the reconcile request before serving it
Addresses the second review finding: a lost update on _pending_plugin_reconcile. The flag was cleared after a successful reconcile. Reconcile has already read its config by that point, so a config change arriving mid-flight set a flag that the trailing clear then erased -- a request that was never served, and the newest config never reconciled. That is the same "my save did nothing" symptom this PR exists to remove, so leaving it would have undercut the fix. Consume the request before running it instead, and re-arm only on a retryable failure. A change that lands during reconcile now stays set and is picked up on the next pass. The per-frame read stays lock-free. It is a fast path that can only produce a false negative -- the watcher setting the flag just after it is read is seen on the next iteration -- never a false positive that loses a request. The lock is taken only when a reconcile is actually pending or a config change arrives. Extracted _service_pending_reconcile() so the sequence is testable rather than buried in run()'s loop; the review asked for a regression test that invokes the subscriber during reconciliation, which is not reachable otherwise. Tests: 4 new, covering a request racing in mid-reconcile, the quiet success, the retryable-failure re-arm, and not reconciling when nothing is pending. Two of them fail against the previous clear-after-success semantics. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01STMbQE4YctTacQXfbYqKuW
This commit is contained in:
co-authored by
Claude Opus 5
parent
7156d31491
commit
094090d138
@@ -385,3 +385,51 @@ class TestReconcileQueuedThroughSubscriber:
|
||||
self._subscriber(controller)(old, new)
|
||||
|
||||
assert controller._pending_plugin_reconcile is False
|
||||
|
||||
|
||||
class TestPendingReconcileNotLost:
|
||||
"""A config change arriving *during* reconcile must not be discarded.
|
||||
|
||||
The flag used to be cleared after a successful reconcile. Reconcile has
|
||||
already read its config by then, so that clear erased a request it never
|
||||
served and the newest config never reconciled -- the same "my save did
|
||||
nothing" symptom this path exists to prevent.
|
||||
"""
|
||||
|
||||
def test_request_arriving_during_reconcile_survives(self, test_display_controller):
|
||||
controller = test_display_controller
|
||||
controller._pending_plugin_reconcile = True
|
||||
|
||||
def reconcile_and_race():
|
||||
# The watcher thread queues another change while we are mid-flight.
|
||||
with controller._reconcile_flag_lock:
|
||||
controller._pending_plugin_reconcile = True
|
||||
return True
|
||||
|
||||
controller._reconcile_enabled_plugins = reconcile_and_race
|
||||
controller._service_pending_reconcile()
|
||||
|
||||
assert controller._pending_plugin_reconcile is True, \
|
||||
"a config change landing during reconcile was discarded"
|
||||
|
||||
def test_flag_cleared_on_a_quiet_success(self, test_display_controller):
|
||||
controller = test_display_controller
|
||||
controller._pending_plugin_reconcile = True
|
||||
controller._reconcile_enabled_plugins = lambda: True
|
||||
controller._service_pending_reconcile()
|
||||
assert controller._pending_plugin_reconcile is False
|
||||
|
||||
def test_retryable_failure_rearms(self, test_display_controller):
|
||||
controller = test_display_controller
|
||||
controller._pending_plugin_reconcile = True
|
||||
controller._reconcile_enabled_plugins = lambda: False
|
||||
controller._service_pending_reconcile()
|
||||
assert controller._pending_plugin_reconcile is True
|
||||
|
||||
def test_no_reconcile_when_nothing_pending(self, test_display_controller):
|
||||
controller = test_display_controller
|
||||
controller._pending_plugin_reconcile = False
|
||||
calls = []
|
||||
controller._reconcile_enabled_plugins = lambda: calls.append(1) or True
|
||||
controller._service_pending_reconcile()
|
||||
assert calls == []
|
||||
|
||||
Reference in New Issue
Block a user