Repository navigation
Avoid bootstrapping pip in model-only Python test venvs (fixes flaky venv timeout) - #21539
Conversation
Model-only AddPythonAppTests only need the .venv directory to exist, but the shared helper ran a full 'python -m venv' (ensurepip spawns pip and writes ~1000 files) under a 2 minute deadline, which timed out on a cold Windows runner. Create those venvs with --without-pip, keep pip for tests that run it, and kill timed-out processes before draining their output. Fixes #19542 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21539Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21539" |
Tests selector1 / 100 PR test projects · 0 PR jobs, from 1 changed file. Selected PR test projects (1 / 100)
Selected PR jobs (0)none How these were chosen — grouped by what changed🧪 Job reasonsnone Selection computed for commit |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the test-only changes that skip unnecessary pip setup in model-only Python environments.
No open issues 🎉
What changed in this PR
Reduces exposure to the flaky Python virtual-environment timeout in #19542 by skipping unnecessary pip setup in Aspire’s model-only Python hosting tests. Changes are test-only.
Changes:
- Creates model-only virtual environments without pip, while preserving pip setup for tests that need it.
- Kills timed-out venv creation and package installation processes before draining their output.
- Adds a regression test verifying that model-only environments contain a Python interpreter but no pip executable.
| File | Description |
|---|---|
tests/Aspire.Hosting.Python.Tests/AddPythonAppTests.cs |
Makes pip setup conditional, fixes timeout handling, and adds regression coverage. |
Review effort: Balanced
|
✅ No documentation update needed. docs_optional → test_only. Triggered signal: |
Description
Fixes #19542
Also fixes a latent hang in the helper's timeout path.
AddPythonAppTests.PythonResourceSupportsWithReferencefailed once onwindows-latest(run 32375588350, job 96448944641) withFailed to create virtual environment.The test took 2m 06s, and the venv process wrote no stdout or stderr.Root cause
AddPythonAppTeststest that usesCreateTempPythonProjectruns a fullpython -m venv .venvand thenpip install, under a fixed 2-minute deadline. Five of those tests only build the app model, and so does the failing one. They need.venvto exist becauseAddPythonAppadds a-venv-creatorresource when it's missing. They never run pip. A fullvenvrunsensurepip, which starts a pip subprocess that installs and byte-compiles about 1,000 files. Without pip, venv creation copies about 5 files. On a cold Windows runner (Defender,MoUsoCoreWorkerand svchost were busy in the heartbeat), this step exceeded 2 minutes. The heartbeat at 14:00:28, 75s into the wait, shows nopythonprocess among the top CPU consumers, so the process was blocked on I/O or the OS rather than computing.Kill. A process that truly hung would therefore block the test until the 20-minute MTP hang timeout instead of failing at 2 minutes. That's why the failure reported 2m 06s: the read waited for python to exit.Fix (test-only)
CreateTempPythonProject(..., withPip: false)is the default for model-only tests. It creates the venv withpython -m venv --without-pip .venvand skipspip install. The venv interpreter exists, so the resource model (command path, no venv-creator) is unchanged.PythonResourceFinishesSuccessfullystarts the app, and its installer resource runs.venvpip. The instrumented test installs requirements.No assertions were changed, and no retries or sleeps were added.
Evidence
Regression test:
CreateTempPythonProject_ForModelOnlyTests_CreatesVirtualEnvironmentWithoutBootstrappingPipasserts that the model-only venv has an interpreter and no pip.-m venv .venv: fails, withModel-only test projects should not bootstrap pip, but found '/tmp/bBYQbR/.venv/bin/pip'.Per-test duration (TRX, Linux, Python 3.12), main → this PR:
Measured separately:
python -m venv .venvwrites 1,010 files in 4.27s, while--without-pipwrites 5 files in 0.05s. Model-only tests no longer start anensurepip/pip subprocess, which was the step that exceeded the deadline.Recurrence: this is the only recorded occurrence. A scan of the last 300
ci.ymlruns (2026-10-30 22:08 to 2026-10-31 06:15 UTC; the CI test selector skips Hosting.Python on most runs) found 0 failures in 20Hosting.Python (windows-latest)jobs. On main, the Windows suite usually takes about 75s (for example, job 124463643298: 1m 15s). The failure is rare and depends on runner conditions, so the evidence above is the removed exposure rather than a local Windows repro.Validation
Aspire.Hosting.Python.Tests(full project, functionalPythonResourceFinishesSuccessfullyincluded, which starts the app via DCP): 119 passed, 0 skipped, 3 failed. The 3 failures areWithUv_GeneratesDockerfileInPublishMode*Verify snapshots. They fail identically on main in this environment because the run is as root and Verify scrubs/root/to{UserProfile}. They're unrelated to this change, and CI is the authority.Windows CI on this PR (job 124468350194):
Hosting.Python (windows-latest)reported 122 succeeded, 0 failed, in 31.6s. On main this suite takes about 75s, so most of the Windows suite time was venv/pip bootstrap that model-only tests didn't need.Checklist
🤖 Posted by AspireAgent (AI Agent)