feat(healing): re-check membership mismatches before healing
A decision created moments before an audit shows up as missing=1 until the bouncer's next poll, which triggered a bouncer restart for nothing. When the audit finds a membership mismatch, wait membership_recheck_delay seconds (default 30, 0 disables) and audit again; only drift that is still present is reported and healed. Metadata drift is not delayed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
79f72512e4
commit
772892b78d
7 files changed
+100
-3
No files matched your search
+46
-1
@@ -3,7 +3,7 @@ import unittest
|
||||
from datetime import datetime
|
||||
from unittest.mock import patch
|
||||
|
||||
from healing import should_heal, execute_heal_and_verify
|
||||
from healing import should_heal, execute_heal_and_verify, recheck_membership_mismatch
|
||||
|
||||
|
||||
class FakeReporter:
|
||||
@@ -158,5 +158,50 @@ class PostHealVerificationTests(unittest.TestCase):
|
||||
self.assertEqual("verify_error", reporter.update_calls[0]["heal_result"])
|
||||
|
||||
|
||||
class MembershipRecheckTests(unittest.TestCase):
|
||||
MISMATCH = (False, 10, {"reason": "membership_mismatch", "missing_count": 1})
|
||||
IN_SYNC = (True, 11, {"reason": "in_sync"})
|
||||
|
||||
def test_recheck_clears_transient_membership_mismatch(self):
|
||||
auditor = FakeAuditor(reconcile_result=self.IN_SYNC)
|
||||
waits = []
|
||||
|
||||
result = recheck_membership_mismatch(
|
||||
auditor, self.MISMATCH, 30, wait=waits.append
|
||||
)
|
||||
|
||||
self.assertEqual(self.IN_SYNC, result)
|
||||
self.assertEqual([30], waits)
|
||||
|
||||
def test_recheck_returns_persisting_drift(self):
|
||||
persisted = (False, 10, {"reason": "membership_mismatch", "missing_count": 2})
|
||||
auditor = FakeAuditor(reconcile_result=persisted)
|
||||
|
||||
result = recheck_membership_mismatch(
|
||||
auditor, self.MISMATCH, 30, wait=lambda _delay: None
|
||||
)
|
||||
|
||||
self.assertEqual(persisted, result)
|
||||
|
||||
def test_recheck_skipped_for_metadata_drift_and_when_disabled(self):
|
||||
auditor = FakeAuditor(reconcile_exception=AssertionError("must not re-audit"))
|
||||
metadata = (False, 10, {"reason": "metadata_drift"})
|
||||
waits = []
|
||||
|
||||
self.assertEqual(
|
||||
metadata,
|
||||
recheck_membership_mismatch(auditor, metadata, 30, wait=waits.append),
|
||||
)
|
||||
self.assertEqual(
|
||||
self.MISMATCH,
|
||||
recheck_membership_mismatch(auditor, self.MISMATCH, 0, wait=waits.append),
|
||||
)
|
||||
self.assertEqual(
|
||||
self.IN_SYNC,
|
||||
recheck_membership_mismatch(auditor, self.IN_SYNC, 30, wait=waits.append),
|
||||
)
|
||||
self.assertEqual([], waits)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user