mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 11:16:47 +00:00
The pool workers were made non-daemonic so the operations process tests could start workers, but a terminated pool (Ctrl-C, --failfast) left those workers running. The test runner now keeps the test cases tagged "processes" out of the pool and runs them in the main process after it. A WAL that cannot be written back before cloning now stops the run instead of giving clones without tables. One CI leg runs the suite with --parallel. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
36 lines
1.7 KiB
Python
36 lines
1.7 KiB
Python
"""manage.py test --parallel on the SQLite database in WAL mode."""
|
|
|
|
from django.test.runner import DiscoverRunner
|
|
|
|
|
|
class TestRunner(DiscoverRunner):
|
|
def build_suite(self, *args, **kwargs):
|
|
suite = super().build_suite(*args, **kwargs)
|
|
if not isinstance(suite, self.parallel_test_suite):
|
|
return suite
|
|
# Pool workers are daemonic and may start no processes: the test
|
|
# cases tagged "processes" run in this process after the pool.
|
|
serial = [case for case in suite.subsuites if "processes" in getattr(next(iter(case)), "tags", ())]
|
|
suite.subsuites = [case for case in suite.subsuites if case not in serial]
|
|
return self.test_suite([suite, *serial])
|
|
|
|
def setup_databases(self, **kwargs):
|
|
# Django clones a SQLite test database by copying its main file, but
|
|
# migrate's writes are still in the WAL file (operations/apps.py):
|
|
# create the database alone, write the WAL back, then clone.
|
|
parallel, self.parallel = self.parallel, 0
|
|
old_config = super().setup_databases(**kwargs)
|
|
self.parallel = parallel
|
|
for connection, _, created in old_config:
|
|
if not created or parallel < 2:
|
|
continue
|
|
if connection.vendor == "sqlite":
|
|
with connection.cursor() as cursor:
|
|
cursor.execute("PRAGMA wal_checkpoint(TRUNCATE)")
|
|
if cursor.fetchone()[0]:
|
|
raise RuntimeError("The test database's WAL could not be written back before cloning")
|
|
for index in range(parallel):
|
|
connection.creation.clone_test_db(
|
|
suffix=str(index + 1), verbosity=self.verbosity, keepdb=self.keepdb
|
|
)
|
|
return old_config
|