test-parallel.sh
bash
sha256:e8c781c3ebb90137401c64c2a72e8883bb5ced6c7c56f1e964cce430bf90adfc
fix(rc25): reserve /_debug; test runner takes the Muse unde…
Opus 5.5
patch
1 day ago
| 1 | #!/bin/zsh |
| 2 | # Run the whole MuseHub test suite in parallel inside the musehub image, against a private Postgres and MinIO. |
| 3 | # |
| 4 | # scripts/dev/test-parallel.sh # everything: parallel + timing-sensitive + migrations phases |
| 5 | # scripts/dev/test-parallel.sh tests/test_foo.py # just these files (parallel phase only) |
| 6 | # WORKERS=12 scripts/dev/test-parallel.sh |
| 7 | # MH_TEST_NS=-wave2 scripts/dev/test-parallel.sh ... # a private network/Postgres/MinIO set, so concurrent runs (agents) never collide |
| 8 | # |
| 9 | # What it sets up (idempotent, all private to the test run; your dev hub, database and MinIO are never touched): |
| 10 | # - docker network mh-tests$MH_TEST_NS |
| 11 | # - postgres mh-testpg$MH_TEST_NS (fsync off; one database per xdist worker, created by tests/conftest.py) |
| 12 | # - minio mh-testminio$MH_TEST_NS (bucket muse-objects) |
| 13 | # Image: musehub/musehub:latest (rebuild with `docker compose build musehub` after dependency changes). |
| 14 | # Muse under test: the CURRENT ~/ecosystem/muse checkout (mounted at /muse, first on PYTHONPATH), never the copy baked into the image. |
| 15 | # |
| 16 | # Phases (the summary adds them up; exit status is 1 if any phase failed): |
| 17 | # 1. parallel -n $WORKERS --dist loadfile every test except the files in phase 2 |
| 18 | # 2. timing -n $PERF_WORKERS files with wall-clock gates (*perf*, *scale*): they miss their limits when the machine is saturated |
| 19 | # 3. migrations -m migrations -n 0 tests that DROP/CREATE databases; serial by design |
| 20 | # Not run by default (explicit opt-in markers, see pyproject.toml): live_hub, install_e2e, host_tools. |
| 21 | set -u |
| 22 | repo=${0:A:h:h:h} |
| 23 | cd "$repo" || exit 2 |
| 24 | workers=${WORKERS:-8} |
| 25 | perf_workers=${PERF_WORKERS:-2} |
| 26 | out=${OUT:-$(mktemp -d "${TMPDIR:-/tmp}/musehub-tests.XXXXXX")} |
| 27 | ns=${MH_TEST_NS:-} # one shared server otherwise, and conftest terminates every other backend before each test |
| 28 | net=mh-tests$ns |
| 29 | pg=mh-testpg$ns |
| 30 | minio=mh-testminio$ns |
| 31 | image=${IMAGE:-musehub/musehub:latest} |
| 32 | ecosystem=${repo:h} |
| 33 | # The Muse under test: the current checkout by default; a release run pins the engine it ships (MUSE_SRC=<pinned checkout>). |
| 34 | muse_src=${MUSE_SRC:-$ecosystem/muse} |
| 35 | |
| 36 | docker network inspect $net >/dev/null 2>&1 || docker network create $net >/dev/null |
| 37 | |
| 38 | if ! docker inspect $pg >/dev/null 2>&1; then |
| 39 | docker run -d --name $pg --network $net --network-alias host.docker.internal \ |
| 40 | -e POSTGRES_USER=musehub -e POSTGRES_PASSWORD=musehub -e POSTGRES_DB=postgres postgres:16-alpine \ |
| 41 | -c max_connections=600 -c fsync=off -c synchronous_commit=off -c full_page_writes=off -c shared_buffers=256MB >/dev/null |
| 42 | fi |
| 43 | docker start $pg >/dev/null 2>&1 |
| 44 | for i in {1..30}; do docker exec $pg pg_isready -U musehub >/dev/null 2>&1 && break; sleep 1; done |
| 45 | for db in musehub musehub_test; do |
| 46 | docker exec $pg psql -U musehub -d postgres -tc "select 1 from pg_database where datname='$db'" | grep -q 1 \ |
| 47 | || docker exec $pg psql -U musehub -d postgres -c "create database $db" >/dev/null |
| 48 | done |
| 49 | |
| 50 | if ! docker inspect $minio >/dev/null 2>&1; then |
| 51 | docker run -d --name $minio --network $net --network-alias minio \ |
| 52 | -e MINIO_ROOT_USER=minioadmin -e MINIO_ROOT_PASSWORD=minioadmin minio/minio:latest server /data >/dev/null |
| 53 | fi |
| 54 | docker start $minio >/dev/null 2>&1 |
| 55 | sleep 3 |
| 56 | docker run --rm --network $net --entrypoint /bin/sh minio/mc:latest -c \ |
| 57 | "mc alias set l http://minio:9000 minioadmin minioadmin >/dev/null && mc mb --ignore-existing l/muse-objects >/dev/null" |
| 58 | |
| 59 | pytest_in_container() { # label, pytest args... |
| 60 | local label=$1; shift |
| 61 | mkdir -p "$out/$label" |
| 62 | docker run --rm --name "mh-tests-$label-$$" --entrypoint python --network $net \ |
| 63 | -v "$repo:/app" -v "$muse_src:/muse:ro" -v "$ecosystem/contracts:/src/contracts:ro" \ |
| 64 | -e TEST_DATABASE_URL=postgresql+asyncpg://musehub:[email protected]:5432/musehub_test \ |
| 65 | -e DATABASE_URL=postgresql+asyncpg://musehub:[email protected]:5432/musehub \ |
| 66 | -e TEST_MINIO_ENDPOINT=http://minio:9000 -e MUSE_CHECKOUT=/muse \ |
| 67 | -e DB_PASSWORD=musehub -e OPENROUTER_API_KEY=dummy -e PYTHONDONTWRITEBYTECODE=1 \ |
| 68 | -e PYTHONPATH=/muse \ |
| 69 | -w /app "$image" -B -m pytest -p no:cacheprovider -ra --timeout=300 "$@" > "$out/$label/log.txt" 2>&1 |
| 70 | local rc=$? |
| 71 | print -r -- "$rc" > "$out/$label/rc" |
| 72 | tail -1 "$out/$label/log.txt" |
| 73 | return $rc |
| 74 | } |
| 75 | |
| 76 | start=$(date +%s) |
| 77 | overall=0 |
| 78 | if (( $# > 0 )); then |
| 79 | pytest_in_container selected -n $workers --dist loadfile "$@" || overall=1 |
| 80 | else |
| 81 | perf_files=(tests/test_*perf*.py tests/test_*scale*.py) |
| 82 | ignores=(); for f in $perf_files; do ignores+=(--ignore="$f"); done |
| 83 | # migrations run beside the parallel phase: they use their own databases on the same server |
| 84 | pytest_in_container migrations -m migrations -n 0 & |
| 85 | mig_pid=$! |
| 86 | pytest_in_container parallel -n $workers --dist loadfile $ignores || overall=1 |
| 87 | pytest_in_container timing -n $perf_workers --dist loadfile $perf_files || overall=1 |
| 88 | wait $mig_pid || overall=1 |
| 89 | fi |
| 90 | print "\nlogs: $out wall: $(( $(date +%s) - start ))s exit: $overall" |
| 91 | exit $overall |
File History
5 commits
sha256:e8c781c3ebb90137401c64c2a72e8883bb5ced6c7c56f1e964cce430bf90adfc
fix(rc25): reserve /_debug; test runner takes the Muse unde…
Opus 5.5
patch
1 day ago
sha256:69676bc7346817557178c2c769cf545a7bf8e8a25ff63c862d267619b6d5a7d6
fix(web): never gate navigation pages; gated pages queue up…
Opus 5.5
minor
⚠
2 days ago
sha256:3362c1a400e967ae2b36624b1d066502e0dff5a08097c8c279f0dc9521e15a6d
test(dev): MH_TEST_NS gives a test run its own network, Pos…
Opus 5.5
patch
2 days ago
sha256:369f691c7aaec3ca84a864ad1d099d5409045ddc12d185a922b3c84b9e2a1bad
merge: 100% passing, parallelized MuseHub test suite (task/…
Sonnet 5.5
patch
3 days ago
sha256:8166b51ae53275831023a7ce334228b3ccc8237b55d68a35172389db9ff46ad5
test: 100% passing MuseHub suite, parallelized (xdist, one …
Sonnet 5.5
patch
3 days ago