mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 17:06:09 +00:00
Django replaces a SQLite test database and its parallel clones by the main file only. A run that is killed, or whose worker pool crashes on a failure it cannot send back, leaves the clones' WAL files behind; the next run's fresh copies then replay that run's writes, and hundreds of tests fail with "Cannot operate on a closed database" or foreign key errors until a clean run checkpoints the stale WAL away. The test runner now removes the test database's and its clones' WAL files before it creates and clones them (not with --keepdb, whose databases they belong to).
21 lines
866 B
Python
21 lines
866 B
Python
"""A killed test run leaves its SQLite WAL files behind; the next run removes
|
|
them before it creates and clones the test database, or SQLite would replay
|
|
the old run's writes into the new one."""
|
|
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
from django.test import SimpleTestCase
|
|
|
|
from webvirtcloud.test_runner import remove_wal_files
|
|
|
|
|
|
class RemoveWalFilesTests(SimpleTestCase):
|
|
def test_the_wal_files_go_and_the_database_stays(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
name = Path(directory) / "test_db_1.sqlite3"
|
|
for path in (name, Path(f"{name}-wal"), Path(f"{name}-shm")):
|
|
path.write_bytes(b"x")
|
|
remove_wal_files(name)
|
|
remove_wal_files(name) # none left: nothing to do
|
|
self.assertEqual(sorted(p.name for p in Path(directory).iterdir()), ["test_db_1.sqlite3"])
|