feat: run the CI suite as parallel processes

validate.yml and pr_checks.py run scripts/run_tests.py with four jobs,
the runner's cores: 24 minutes here for the suite that took about 40 in
one process. A failed module's tracebacks are printed in the summary, as
a runner keeps no log file. The two scripts added today follow the rules
the suite holds every script to (no abbreviated option, run_cli, every
option documented), and the two isolation tests drop the per-module
scratch variable to check the folder a module gets alone.
This commit is contained in:
Abdessamad Derraz committed 2026-11-12 15:36:46 +01:00
1 parent fb33ee58e1
commit abbfebff3e
11 files changed
+63 -27

No files matched your search

+4 -1
View File
@@ -332,9 +332,12 @@ jobs:
# No test downloads a release asset: 252 MB files fetched into the
# shared cache filled the runner's disk and changed what later tests
# resolved. The download tests mock the network and clear it.
# One process per module, four at a time on the runner's four cores,
# each with its own scratch folder: a module that leaves a variable
# set no longer changes the ones after it.
env:
RETROBIOS_OFFLINE: "1"
run: python -m unittest discover -s tests -t . -v
run: python scripts/run_tests.py --jobs 4
- name: Run the full-screen interface tests on Python 3.8
if: ${{ !cancelled() }}
+1 -1
View File
@@ -91,7 +91,7 @@ python scripts/refresh_data_dirs.py # data directories the
python scripts/generate_site.py # the pages the site tests read
npm ci --prefix website # the site's packages, Node 24
npm run build --prefix website # the built site
python -m unittest discover -s tests -t . # the suite
python scripts/run_tests.py --jobs 4 # the suite, one process per module
python3.8 -m unittest tests.test_install_tui # the full screen on the installer's floor
python scripts/validate_site.py --site-dir website/dist # links and page budgets
```
+6 -2
View File
@@ -86,7 +86,8 @@ def sources(paths: list[Path]) -> Iterator[tuple[str, bytes]]:
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__.split("\n\n", 1)[0])
parser = argparse.ArgumentParser(allow_abbrev=False,
description=__doc__.split("\n\n", 1)[0])
parser.add_argument("paths", nargs="+", type=Path, help="files, folders or ZIPs to search")
parser.add_argument("--crc32", required=True, help="crc32 of the wanted file, in hex")
parser.add_argument("--size", required=True, type=int, help="size of the wanted file, in bytes")
@@ -125,4 +126,7 @@ def main() -> int:
if __name__ == "__main__":
sys.exit(main())
sys.path.insert(0, str(Path(__file__).resolve().parent))
from common import run_cli
run_cli(main)
+1 -1
View File
@@ -60,7 +60,7 @@ STEPS: tuple[Step, ...] = (
# filled it and every later command failed with ENOSPC.
Step("npm run build --prefix website", "the built site",
needs="npm", provider="Node 24", env={"NODE_DISABLE_COMPILE_CACHE": "1"}),
Step("python -m unittest discover -s tests -t .", "the suite",
Step("python scripts/run_tests.py --jobs 4", "the suite, one process per module",
env={"RETROBIOS_OFFLINE": "1"}),
Step("python3.8 -m unittest tests.test_install_tui", "the full screen on the installer's floor",
needs="python3.8", provider="a Python 3.8 with pyte",
+21 -6
View File
@@ -6,12 +6,12 @@ Usage:
python scripts/run_tests.py --jobs 1 # one at a time, as discover runs
python scripts/run_tests.py tests.test_install tests.test_e2e
`python -m unittest discover` runs 8,500 tests in one process: about 40
minutes here and 85 on the CI runner, and a module that left a variable or a
flag set changed the modules after it. Here each module gets a fresh process
unittest's discovery runs 8,500 tests in one process: about 40 minutes
here and 85 on the CI runner, and a module that left a variable or a flag
set changed the modules after it. Here each module gets a fresh process
and its own scratch folder (RETROBIOS_TEST_SCRATCH, read by tests/__init__),
the longest first so the last ones to start are short. Durations are kept in
tmp/test-durations.json, from the previous run; a module never timed is
tmp/test-durations.json, from the previous run, and a module never timed is
weighed by its size.
The host computes wrong and Python segfaults under load: a module killed by
@@ -41,6 +41,8 @@ DURATIONS = ROOT / "tmp" / "test-durations.json"
# third of the cores at once made them fail for no other reason.
DEFAULT_JOBS = max(1, min(6, (os.cpu_count() or 2) // 3))
# Lines of a failed module's tracebacks printed in the summary.
FAILURE_LINES = 200
_RAN = re.compile(r"^Ran (\d+) tests? in ([\d.]+)s$", re.M)
_COUNTS = re.compile(r"(failures|errors|skipped|expected failures|unexpected successes)=(\d+)")
@@ -117,7 +119,8 @@ def run_module(module: str, env: dict[str, str], logs: Path) -> Result:
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__.split("\n\n", 1)[0])
parser = argparse.ArgumentParser(allow_abbrev=False,
description=__doc__.split("\n\n", 1)[0])
parser.add_argument("modules", nargs="*", help="modules to run (tests.test_x), all by default")
parser.add_argument("--jobs", "-j", type=int, default=DEFAULT_JOBS,
help=f"modules at once (default {DEFAULT_JOBS})")
@@ -169,9 +172,21 @@ def main() -> int:
print(f"FAILED {result.module}: {result.failures} failures, {result.errors} errors "
f"(code {result.code if result.crashed_then is None else result.crashed_then}), "
f"log {result.log.relative_to(ROOT) if result.log else '-'}")
# A CI runner shows the output and keeps no file: what failed, and
# why, is said here, the tracebacks unittest wrote, at most a page.
if result.log is not None:
text = result.log.read_text(encoding="utf-8", errors="replace")
start = text.find("\n" + "=" * 70)
shown = (text[start:] if start >= 0 else text).strip().splitlines()
for line in shown[:FAILURE_LINES]:
print(f" {line}")
if len(shown) > FAILURE_LINES:
print(f" ... {len(shown) - FAILURE_LINES} more lines in the log")
print("OK" if not failed else f"FAILED ({len(failed)} modules)")
return 1 if failed else 0
if __name__ == "__main__":
sys.exit(main())
from common import run_cli
run_cli(main)
+8 -4
View File
@@ -241,11 +241,14 @@ class AModuleRunAloneHasItsScratchDirectory(unittest.TestCase):
(clone / "tests" / "__init__.py").write_bytes(
(ROOT / "tests" / "__init__.py").read_bytes()
)
# The folder a module gets alone, not the one scripts/run_tests.py
# names for each module it runs beside others.
env = {k: v for k, v in os.environ.items() if k != "RETROBIOS_TEST_SCRATCH"}
proc = subprocess.run(
[sys.executable, "-I", "-c",
"import sys; sys.path.insert(0, '.'); import tests, tempfile, os;"
" print(tempfile.gettempdir()); print(os.environ['TMPDIR'])"],
cwd=clone, capture_output=True, text=True, timeout=60, check=False,
cwd=clone, env=env, capture_output=True, text=True, timeout=60, check=False,
)
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertTrue((clone / "tmp" / "tests").is_dir())
@@ -278,7 +281,8 @@ class EveryTestModuleImportsTheIsolation(unittest.TestCase):
def test_discover_without_a_top_level_runs_isolated(self):
env = {k: v for k, v in os.environ.items()
if k not in ("RETROBIOS_OFFLINE", "TMPDIR", "RETROBIOS_CACHE")}
if k not in ("RETROBIOS_OFFLINE", "TMPDIR", "RETROBIOS_CACHE",
"RETROBIOS_TEST_SCRATCH")}
proc = subprocess.run(
[sys.executable, "-c",
"import os, sys, tempfile, unittest\n"
@@ -402,7 +406,7 @@ class WorkflowRegressions(unittest.TestCase):
name
for name, body in workflow["jobs"].items()
if any(
"unittest discover" in str(step.get("run", ""))
"scripts/run_tests.py" in str(step.get("run", ""))
for step in body.get("steps", [])
)
),
@@ -4794,7 +4798,7 @@ class TheTestJobHasTheDataTrees(unittest.TestCase):
)["jobs"]["run-tests"]["steps"]
runs = [step.get("run", "") for step in steps]
fetch = next(i for i, run in enumerate(runs) if "refresh_data_dirs.py" in run)
suite = next(i for i, run in enumerate(runs) if "unittest discover" in run)
suite = next(i for i, run in enumerate(runs) if "scripts/run_tests.py" in run)
self.assertLess(fetch, suite)
+3 -3
View File
@@ -68,7 +68,7 @@ class BeforeOpeningAPullRequest(unittest.TestCase):
section = text.split("## Before opening a PR", 1)[1].split("\n## ", 1)[0]
block = "".join(_re.findall(r"```bash\n(.*?)```", section, _re.S))
for command in ("validate_pr.py --changed", "validate_schemas.py --source-only",
"unittest discover"):
"run_tests.py"):
self.assertIn(command, block)
self.assertNotIn("pipeline.py", block)
workflow = (REPO_ROOT / ".github" / "workflows" / "validate.yml").read_text(encoding="utf-8")
@@ -268,13 +268,13 @@ class OneCommandRunsTheChecks(unittest.TestCase):
workflow = (REPO_ROOT / ".github" / "workflows" / "validate.yml").read_text(encoding="utf-8")
order = [workflow.index(key) for key in (
"refresh_data_dirs.py", "run: python scripts/generate_site.py",
"npm run build --prefix website", "python -m unittest discover",
"npm run build --prefix website", "python scripts/run_tests.py",
"validate_site.py")]
self.assertEqual(order, sorted(order))
commands = [step.command for step in pr_checks.STEPS]
positions = [next(i for i, c in enumerate(commands) if key in c) for key in (
"refresh_data_dirs.py", "generate_site.py", "npm run build",
"unittest discover", "validate_site.py")]
"run_tests.py", "validate_site.py")]
self.assertEqual(positions, sorted(positions))
def test_the_guide_gives_the_runner_and_what_it_runs(self):
+6 -6
View File
@@ -397,14 +397,14 @@ class ContributorChecksMatchCi(unittest.TestCase):
block = _section(text, "## Before opening a PR")
self.assertIn("python scripts/refresh_data_dirs.py", block)
self.assertLess(
block.index("refresh_data_dirs.py"), block.index("unittest discover")
block.index("refresh_data_dirs.py"), block.index("run_tests.py")
)
def test_ci_does_the_same(self):
workflow = _read(".github/workflows/validate.yml")
self.assertLess(
workflow.index("python scripts/refresh_data_dirs.py"),
workflow.index("python -m unittest discover"),
workflow.index("python scripts/run_tests.py"),
)
def test_the_pr_checklist_generates_the_site_before_the_tests(self):
@@ -413,7 +413,7 @@ class ContributorChecksMatchCi(unittest.TestCase):
workflow = _read(".github/workflows/validate.yml")
self.assertLess(
workflow.index("run: python scripts/generate_site.py"),
workflow.index("python -m unittest discover"),
workflow.index("python scripts/run_tests.py"),
)
for text in (
contributing_text(lambda page: page, "# C", "here"),
@@ -422,7 +422,7 @@ class ContributorChecksMatchCi(unittest.TestCase):
block = _section(text, "## Before opening a PR")
self.assertIn("python scripts/generate_site.py", block)
self.assertLess(
block.index("generate_site.py"), block.index("unittest discover")
block.index("generate_site.py"), block.index("run_tests.py")
)
@@ -626,7 +626,7 @@ class ContributorChecksFetchThePlatformsFiles(unittest.TestCase):
workflow = _read(".github/workflows/validate.yml")
self.assertLess(
workflow.index("python scripts/export_native.py --all --refresh-cache"),
workflow.index("python -m unittest discover"),
workflow.index("python scripts/run_tests.py"),
)
for text in (
contributing_text(lambda page: page, "# C", "here"),
@@ -635,7 +635,7 @@ class ContributorChecksFetchThePlatformsFiles(unittest.TestCase):
block = _section(text, "## Before opening a PR")
self.assertIn("python scripts/export_native.py --all --refresh-cache", block)
self.assertLess(
block.index("export_native.py"), block.index("unittest discover")
block.index("export_native.py"), block.index("run_tests.py")
)
def test_the_testing_guide_names_the_command(self):
+1 -1
View File
@@ -147,7 +147,7 @@ class ThePullRequestBuildsTheSite(unittest.TestCase):
generate = next(
i for i, run in enumerate(runs) if "scripts/generate_site.py" in run
)
suite = next(i for i, run in enumerate(runs) if "unittest discover" in run)
suite = next(i for i, run in enumerate(runs) if "scripts/run_tests.py" in run)
self.assertLess(generate, suite)
# The built pages too: about fifty tests read website/dist.
build = next(i for i, run in enumerate(runs) if "npm run build" in run)
+9 -1
View File
@@ -23,6 +23,14 @@ Run the full suite:
python -m unittest discover -s tests -t . -v
```
Or run it as parallel processes, one per module, each with its own
scratch folder. A module a host crash kills runs again alone at the end:
```bash
python scripts/run_tests.py # a few modules at a time
python scripts/run_tests.py --jobs 1 # one at a time
```
Run a single module, or several:
```bash
@@ -69,7 +77,7 @@ Every module in `tests/`, by the area it guards.
| Pack probe | the cores a platform runs for a system, staging grown to a fixed point, runs mapped to pack and manifest entries, the line and its schema, the probe lock per run, that no page shows its lines. One class builds a real pack narrowed to PlayStation and lays it out both ways, from the archive and with `install.py --dest`, and skips without the collection | `test_pack_probe` |
| Automation runner, disk cleanup, asset sync and bit-flip repair | fake jobs, git repositories with a bare origin and session worktrees, a committed file with one bit flipped, canned CI runs in place of `gh` | `test_autorun` |
| Truth and native export | synthetic + cached originals | `test_export_counts`, `test_export_native_layer`, `test_export_report`, `test_exporters`, `test_truth_data_dir_readers`, `test_truth_diff`, `test_truth_layout` |
| Scrapers, upstream and provenance | inline sources, synthetic | `test_batocera_md5_list`, `test_check_freshness`, `test_cited_lines`, `test_contributing_text`, `test_coverage_cache`, `test_data_dir_refs`, `test_dataclass_defaults`, `test_dedup`, `test_doc_pages`, `test_doc_surfaces`, `test_elec_scrapers`, `test_fbneo_parser`, `test_find_pinned_revision`, `test_hash_merge`, `test_launchers`, `test_launchers_amberelec`, `test_launchers_emudeck`, `test_launchers_emuelec`, `test_launchers_knulli`, `test_launchers_recalbox`, `test_launchers_retrobat`, `test_launchers_retrodeck`, `test_launchers_retropie`, `test_launchers_rocknix`, `test_mame_devices`, `test_mame_parser`, `test_mame_ref_audit`, `test_optional_dependencies`, `test_pin_build`, `test_profile_sync`, `test_prose_style`, `test_provenance`, `test_refresh_data_dirs`, `test_refresh_failures`, `test_refresh_stale`, `test_retired_files`, `test_retrodeck_scraper_errors`, `test_romset_recipes`, `test_schema_semantic_gate`, `test_scraper_contract`, `test_site_agents`, `test_site_arcade_boards`, `test_site_availability`, `test_site_bootstrap`, `test_site_built_gate`, `test_site_components`, `test_site_console_folders`, `test_site_content_data`, `test_site_copy`, `test_site_cores`, `test_site_css`, `test_site_demo`, `test_site_density_cards`, `test_site_emulator_page`, `test_site_emulators`, `test_site_entry`, `test_site_entry_tables`, `test_site_exports`, `test_site_freshness`, `test_site_funnel`, `test_site_images`, `test_site_inputs`, `test_site_insights`, `test_site_integration`, `test_site_nav`, `test_site_page_text`, `test_site_picker`, `test_site_platform_density`, `test_site_platform_hashes`, `test_site_privacy`, `test_site_pronouns`, `test_site_reference`, `test_site_render`, `test_site_search`, `test_site_steps`, `test_site_system_links`, `test_site_system_names`, `test_site_system_sections`, `test_site_systems`, `test_site_validation`, `test_site_weight`, `test_site_wiki`, `test_site_write`, `test_source_ref_targets`, `test_upstream`, `test_upstream_index`, `test_validate_pr`, `test_validate_pr_flow`, `test_validate_pr_hashes`, `test_version_basis`, `test_workflow_paths` |
| Scrapers, upstream and provenance | inline sources, synthetic | `test_auto_fetch_lookup`, `test_batocera_md5_list`, `test_find_embedded`, `test_check_freshness`, `test_cited_lines`, `test_contributing_text`, `test_coverage_cache`, `test_data_dir_refs`, `test_dataclass_defaults`, `test_dedup`, `test_doc_pages`, `test_doc_surfaces`, `test_elec_scrapers`, `test_fbneo_parser`, `test_find_pinned_revision`, `test_hash_merge`, `test_launchers`, `test_launchers_amberelec`, `test_launchers_emudeck`, `test_launchers_emuelec`, `test_launchers_knulli`, `test_launchers_recalbox`, `test_launchers_retrobat`, `test_launchers_retrodeck`, `test_launchers_retropie`, `test_launchers_rocknix`, `test_mame_devices`, `test_mame_parser`, `test_mame_ref_audit`, `test_optional_dependencies`, `test_pin_build`, `test_profile_sync`, `test_prose_style`, `test_provenance`, `test_refresh_data_dirs`, `test_refresh_failures`, `test_refresh_stale`, `test_retired_files`, `test_retrodeck_scraper_errors`, `test_romset_recipes`, `test_schema_semantic_gate`, `test_scraper_contract`, `test_site_agents`, `test_site_arcade_boards`, `test_site_availability`, `test_site_bootstrap`, `test_site_built_gate`, `test_site_components`, `test_site_console_folders`, `test_site_content_data`, `test_site_copy`, `test_site_cores`, `test_site_css`, `test_site_demo`, `test_site_density_cards`, `test_site_emulator_page`, `test_site_emulators`, `test_site_entry`, `test_site_entry_tables`, `test_site_exports`, `test_site_freshness`, `test_site_funnel`, `test_site_images`, `test_site_inputs`, `test_site_insights`, `test_site_integration`, `test_site_nav`, `test_site_page_text`, `test_site_picker`, `test_site_platform_density`, `test_site_platform_hashes`, `test_site_privacy`, `test_site_pronouns`, `test_site_reference`, `test_site_render`, `test_site_search`, `test_site_steps`, `test_site_system_links`, `test_site_system_names`, `test_site_system_sections`, `test_site_systems`, `test_site_validation`, `test_site_weight`, `test_site_wiki`, `test_site_write`, `test_source_ref_targets`, `test_upstream`, `test_upstream_index`, `test_validate_pr`, `test_validate_pr_flow`, `test_validate_pr_hashes`, `test_version_basis`, `test_workflow_paths` |
| Games on the card | small DATs, listxml and setup sources, a fake fetcher, fixture install lists, and the committed data against its schemas | `test_arcade_parents`, `test_game_catalogs`, `test_game_headers`, `test_game_regions`, `test_games_index`, `test_romfolders_card`, `test_romfolders_es` |
## Test architecture
+3 -1
View File
@@ -1397,7 +1397,9 @@ Further options, by script:
| Script | Options |
|--------|---------|
| `auto_fetch.py` | `--create-issues` prints a GitHub issue body per platform for the files still missing, with their full hashes. It posts nothing |
| `auto_fetch.py` | `--create-issues` prints a GitHub issue body per platform for the files still missing, with their full hashes. It posts nothing. `--sha1` looks a file up by its hash alone, in the database, Software Heritage and archive.org, and writes what it finds to `tmp/acquire/` |
| `find_embedded.py` | `--crc32` and `--size` name the file looked for inside other files (every offset, ZIP members read), `--sha1` confirms a hit, `--extract` writes a confirmed one to `tmp/acquire/` |
| `run_tests.py` | `--jobs` sets how many test modules run at once (default a third of the cores, at most 6) |
| `check_buildbot_system.py` | `--update` refreshes the entries found stale, `--json`, `--registry` |
| `check_freshness.py` | `--cache-dir`, `--native-cache-dir` (originals of the native export) and `--truth-dir` move the caches it reads |
| `check_release.py` | `--tag`, `--sums dist/SHA256SUMS.txt`, `--record` (default `release.json`), `--json` |