fix(healing): handle post-heal verify exceptions without crashing loop
This commit is contained in:
1 parent
9edce6b31d
commit
9b53a4c491
2 files changed
+51
-13
No files matched your search
+24
-1
@@ -15,9 +15,10 @@ class FakeReporter:
|
||||
|
||||
|
||||
class FakeAuditor:
|
||||
def __init__(self, heal_ok=True, reconcile_result=None):
|
||||
def __init__(self, heal_ok=True, reconcile_result=None, reconcile_exception=None):
|
||||
self.heal_ok = heal_ok
|
||||
self.reconcile_result = reconcile_result
|
||||
self.reconcile_exception = reconcile_exception
|
||||
self.last_heal_drift = None
|
||||
|
||||
def heal(self):
|
||||
@@ -28,6 +29,8 @@ class FakeAuditor:
|
||||
return self.heal_ok
|
||||
|
||||
def reconcile(self):
|
||||
if self.reconcile_exception:
|
||||
raise self.reconcile_exception
|
||||
return self.reconcile_result
|
||||
|
||||
|
||||
@@ -108,6 +111,26 @@ class PostHealVerificationTests(unittest.TestCase):
|
||||
self.assertEqual("not_verified", returned_post_drift["reason"])
|
||||
self.assertEqual([(False, 7, "Bouncer restart failed")], reporter.update_calls)
|
||||
|
||||
@patch("healing.time.sleep", return_value=None)
|
||||
def test_execute_heal_and_verify_verify_exception(self, _sleep):
|
||||
reporter = FakeReporter()
|
||||
auditor = FakeAuditor(heal_ok=True, reconcile_exception=RuntimeError("boom"))
|
||||
|
||||
heal_result, returned_post_drift = execute_heal_and_verify(
|
||||
auditor,
|
||||
reporter,
|
||||
count=7,
|
||||
drift={"fingerprint": "pre123"},
|
||||
heal_verify_delay=0,
|
||||
)
|
||||
|
||||
self.assertEqual("verify_error", heal_result)
|
||||
self.assertEqual("verify_error", returned_post_drift["reason"])
|
||||
self.assertEqual(1, len(reporter.update_calls))
|
||||
self.assertFalse(reporter.update_calls[0][0])
|
||||
self.assertEqual(7, reporter.update_calls[0][1])
|
||||
self.assertIn("Post-heal verify error: boom", reporter.update_calls[0][2])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user