Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provision lock #2516

Merged
merged 7 commits into from Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/tox/session/commands/provision.py
Expand Up @@ -4,6 +4,8 @@
import os

from tox.exception import InvocationError
from tox.reporter import verbosity0
from tox.util.lock import hold_lock


def provision_tox(provision_venv, args):
Expand All @@ -21,5 +23,9 @@ def provision_tox(provision_venv, args):


def ensure_meta_env_up_to_date(provision_venv):
if provision_venv.setupenv():
provision_venv.finishvenv()
config = provision_venv.envconfig.config
lock_file = config.toxworkdir.join("{}.lock".format(config.provision_tox_env))

with hold_lock(lock_file, verbosity0):
if provision_venv.setupenv():
provision_venv.finishvenv()
32 changes: 32 additions & 0 deletions tests/integration/test_provision_int.py
Expand Up @@ -134,3 +134,35 @@ def test_provision_interrupt_child(initproj, monkeypatch, capfd, signal_type):
out,
"\n".join(repr(i) for i in all_process),
)


@pytest.mark.skipif("sys.platform == 'win32'", reason="pyenv does not exists on Windows")
def test_provision_race(initproj, cmd, monkeypatch):
initproj(
"pkg123-0.7",
filedefs={
"tox.ini": """\
[tox]
skipsdist=True
minversion = 3.7.0
requires =
setuptools == 40.6.3
[testenv]
commands=python -c "import sys; print(sys.executable); raise SystemExit(1)"
[testenv:x2]
""",
},
)

procs = [
subprocess.Popen(
[sys.executable, "-m", "tox", "-e", "py", "-vv"],
stdout=subprocess.PIPE,
encoding="utf-8",
)
for _ in range(2)
]
for proc in procs:
stdout, stderr = proc.communicate()
assert proc.returncode != 0
assert ".tox/.tox/bin/python -m virtualenv" in stdout