Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions tests/control_integration/test_control_backup_snapshot.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from contextlib import closing
import gc
import hashlib
import importlib.util
import json
import os
from pathlib import Path
import sqlite3
import subprocess
import sys
import tempfile
import unittest
from unittest import mock
Expand All @@ -25,11 +28,22 @@ def load_snapshot_module():
@unittest.skipIf(os.name == "nt", "Linux control backup snapshot contract")
class ControlBackupSnapshotTests(unittest.TestCase):
def setUp(self):
unraisable = []
previous_hook = sys.unraisablehook
sys.unraisablehook = lambda event: unraisable.append(event.exc_type)
def check_finalizers():
try:
gc.collect()
self.assertEqual(unraisable, [])
finally:
sys.unraisablehook = previous_hook
self.addCleanup(check_finalizers)
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
self.root = Path(self.temp.name)
self.module = load_snapshot_module()
self.db = self.root / "source.sqlite"
with sqlite3.connect(self.db) as connection:
with closing(sqlite3.connect(self.db)) as connection, connection:
connection.executescript("""
CREATE TABLE session_peer_migrations(
version INTEGER PRIMARY KEY, appliedAt INTEGER NOT NULL
Expand Down Expand Up @@ -89,7 +103,7 @@ def test_snapshot_records_schema_integrity_key_and_revision_fence(self):
self.assertTrue(contract["replayDigestPresent"])

def test_snapshot_rejects_schema_and_revision_rollback(self):
with sqlite3.connect(self.db) as connection:
with closing(sqlite3.connect(self.db)) as connection, connection:
connection.execute("UPDATE session_peer_migrations SET version=2")
with self.assertRaisesRegex(RuntimeError, "control_schema_migration_required"):
self.module.database_snapshot(self.root / "future")
Expand Down
Loading