Archive verified rollbacks of interrupted activation journals
ABSDEV Framework CI / framework-ci (push) Successful in 20s
ABSDEV Framework CI / framework-ci (push) Successful in 20s
This commit is contained in:
@@ -120,7 +120,7 @@ class RecoveryTests(unittest.TestCase):
|
||||
runtime_check=self.runtime_check,
|
||||
)
|
||||
|
||||
def prepare(self, failed=True):
|
||||
def prepare(self, failed=True, *, interrupted=False):
|
||||
|
||||
transaction = self.journal.create(
|
||||
"example-absdev-net",
|
||||
@@ -150,6 +150,8 @@ class RecoveryTests(unittest.TestCase):
|
||||
)
|
||||
|
||||
self.releases.activate("2")
|
||||
if interrupted:
|
||||
return transaction
|
||||
|
||||
transaction = self.journal.transition(
|
||||
transaction["transaction_id"],
|
||||
|
||||
@@ -4,6 +4,7 @@ import unittest
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import test_rollback
|
||||
import test_recovery
|
||||
|
||||
from core.rollback_archive import RollbackArchive, ArchiveError
|
||||
from core.compatibility import canonical_hash
|
||||
@@ -250,3 +251,41 @@ class RollbackArchiveTests(unittest.TestCase):
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
class InterruptedRollbackArchiveTests(unittest.TestCase):
|
||||
def test_confirmed_rollback_can_archive_interrupted_activation(self):
|
||||
prepare = test_recovery.RecoveryTests.prepare
|
||||
|
||||
def interrupted(recovery):
|
||||
return prepare(recovery, interrupted=True)
|
||||
|
||||
fixture = RollbackArchiveTests()
|
||||
self.addCleanup(fixture.doCleanups)
|
||||
with patch.object(test_recovery.RecoveryTests, "prepare", interrupted):
|
||||
fixture.setUp()
|
||||
self.assertEqual(fixture.transaction["phase"], "ACTIVATING")
|
||||
result = fixture.execute()
|
||||
self.assertEqual(result["transaction"]["phase"], "ACTIVATING")
|
||||
self.assertIsNone(fixture.journal.load())
|
||||
self.assertTrue(fixture.marker.is_file())
|
||||
self.assertEqual(fixture.archive.load(fixture.identifier), result)
|
||||
|
||||
|
||||
def test_unfinished_migration_blocks_rollback_journal_retirement(self):
|
||||
from core.approval_store import ApprovalStore
|
||||
|
||||
fixture = RollbackArchiveTests()
|
||||
self.addCleanup(fixture.doCleanups)
|
||||
fixture.setUp()
|
||||
approvals = fixture.recovery.root / "approvals"
|
||||
approvals.mkdir(mode=0o700, exist_ok=True)
|
||||
fixture.journal.bind_migration_guard(ApprovalStore(approvals))
|
||||
blocker = approvals / ("b" * 32 + ".migration-intent.json")
|
||||
blocker.write_text("{}")
|
||||
before = fixture.journal.path.read_bytes()
|
||||
with self.assertRaises(ArchiveError):
|
||||
fixture.execute()
|
||||
self.assertEqual(fixture.journal.path.read_bytes(), before)
|
||||
self.assertFalse(fixture.marker.exists())
|
||||
self.assertFalse(fixture.archive.path(fixture.identifier).exists())
|
||||
|
||||
Reference in New Issue
Block a user