mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-21 20:42:17 +01:00
test_changed: private TMPDIR, 2 flutter isolates
Some checks are pending
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,dependency-freshness) (push) Waiting to run
Tests / test (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Some checks are pending
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,dependency-freshness) (push) Waiting to run
Tests / test (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
A bare targeted flutter test on the shared /tmp held a build slot 67 s under the build queue (perf.heavybuild, 2026-11-21) against ~4 s alone. Match the ci_mirror.sh shards: own TMPDIR, --concurrency=2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a9f82f52d2
commit
88da2564a1
@ -2,7 +2,7 @@ name: diet_guard_app
|
||||
description: "Companion phone app for diet_guard: log meals on the go."
|
||||
publish_to: 'none'
|
||||
|
||||
version: 1.0.190+1
|
||||
version: 1.0.191+1
|
||||
|
||||
environment:
|
||||
sdk: ^3.12.2
|
||||
|
||||
86
diet_guard/tests/test_test_changed_flutter.py
Normal file
86
diet_guard/tests/test_test_changed_flutter.py
Normal file
@ -0,0 +1,86 @@
|
||||
"""scripts/test_changed.sh runs flutter like a CI-mirror shard does.
|
||||
|
||||
A bare ``flutter test`` on the shared /tmp stalled a 3-file run to 67 s under
|
||||
the build queue (2026-11-21, perf.heavybuild) while the same files take ~4 s
|
||||
alone; the shards fixed that with a private TMPDIR and two isolates, and the
|
||||
targeted runner must do the same.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
REPO = Path(__file__).resolve().parents[2]
|
||||
GIT = shutil.which("git") or "git"
|
||||
BASH = shutil.which("bash") or "bash"
|
||||
FAKE_FLUTTER = """#!/bin/bash
|
||||
printf 'TMPDIR=%s\\n' "${TMPDIR:-}" >> "$FLUTTER_LOG"
|
||||
printf 'ARGS=%s\\n' "$*" >> "$FLUTTER_LOG"
|
||||
"""
|
||||
|
||||
|
||||
def _shared_tmp(tmp_path: Path) -> Path:
|
||||
"""Stand-in for the machine-wide /tmp the caller would pass down."""
|
||||
shared = tmp_path / "shared-tmp"
|
||||
shared.mkdir(exist_ok=True)
|
||||
return shared
|
||||
|
||||
|
||||
def _git(cwd: Path, *args: str) -> None:
|
||||
subprocess.run([GIT, *args], cwd=cwd, check=True, capture_output=True)
|
||||
|
||||
|
||||
def _run_test_changed(tmp_path: Path) -> dict[str, str]:
|
||||
repo = tmp_path / "repo"
|
||||
(repo / "scripts").mkdir(parents=True)
|
||||
(repo / "app" / "test").mkdir(parents=True)
|
||||
shutil.copy(REPO / "scripts" / "test_changed.sh", repo / "scripts")
|
||||
_git(repo, "init", "-q")
|
||||
_git(
|
||||
repo,
|
||||
"-c",
|
||||
"user.name=t",
|
||||
"-c",
|
||||
"user.email=t@t",
|
||||
"commit",
|
||||
"-q",
|
||||
"--allow-empty",
|
||||
"-m",
|
||||
"init",
|
||||
)
|
||||
(repo / "app" / "test" / "a_test.dart").write_text("void main() {}\n")
|
||||
bin_dir = tmp_path / "bin"
|
||||
bin_dir.mkdir()
|
||||
fake = bin_dir / "flutter"
|
||||
fake.write_text(FAKE_FLUTTER)
|
||||
fake.chmod(0o755)
|
||||
log = tmp_path / "flutter.log"
|
||||
env = {
|
||||
**os.environ,
|
||||
"PATH": f"{bin_dir}:{os.environ['PATH']}",
|
||||
"FLUTTER_LOG": str(log),
|
||||
"TMPDIR": str(_shared_tmp(tmp_path)),
|
||||
}
|
||||
subprocess.run(
|
||||
[BASH, "scripts/test_changed.sh"],
|
||||
cwd=repo,
|
||||
env=env,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
return dict(line.split("=", 1) for line in log.read_text().splitlines())
|
||||
|
||||
|
||||
def test_flutter_gets_a_private_tmpdir_that_is_removed(tmp_path: Path) -> None:
|
||||
seen = _run_test_changed(tmp_path)
|
||||
assert seen["TMPDIR"] not in {"", str(_shared_tmp(tmp_path))}
|
||||
assert not Path(seen["TMPDIR"]).exists()
|
||||
|
||||
|
||||
def test_flutter_runs_two_isolates_on_the_changed_file(tmp_path: Path) -> None:
|
||||
seen = _run_test_changed(tmp_path)
|
||||
assert "--concurrency=2" in seen["ARGS"]
|
||||
assert "test/a_test.dart" in seen["ARGS"]
|
||||
@ -22,8 +22,16 @@ pytest_run() {
|
||||
}
|
||||
|
||||
# Dart changes map to app/test/<name>_test.dart; any other app/ change runs the app suite.
|
||||
# A private TMPDIR and two isolates, as each ci_mirror.sh shard does: on the
|
||||
# shared /tmp a 3-file run stalled to 67 s in the build queue (2026-11-21)
|
||||
# against ~4 s alone, and the default isolate count overruns capped.sh's 2 GiB.
|
||||
flutter_run() {
|
||||
(cd app && flutter test --reporter=compact "$@")
|
||||
local tmp status=0
|
||||
tmp="$(mktemp -d "${XDG_CACHE_HOME:-$HOME/.cache}/diet-guard-flutter-test.XXXXXX")"
|
||||
(cd app && TMPDIR="$tmp" flutter test --reporter=compact \
|
||||
--concurrency="${FLUTTER_TEST_CONCURRENCY:-2}" "$@") || status=$?
|
||||
rm -rf -- "$tmp"
|
||||
return "$status"
|
||||
}
|
||||
|
||||
if grep -qs testmon pyproject.toml requirements*.txt; then
|
||||
|
||||
Loading…
Reference in New Issue
Block a user