Skip to content

Commit 9c6a6e5

Browse files
authored
Merge pull request #3099 from abravalheri/flaky-test-build-meta
Add timeout to `test_build_meta`
2 parents 4f78331 + 8a3cbd0 commit 9c6a6e5

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

setuptools/tests/test_build_meta.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import os
22
import shutil
3+
import signal
34
import tarfile
45
import importlib
6+
import contextlib
57
from concurrent import futures
68
import re
79

@@ -11,6 +13,9 @@
1113
from .textwrap import DALS
1214

1315

16+
TIMEOUT = int(os.getenv("TIMEOUT_BACKEND_TEST", "180")) # in seconds
17+
18+
1419
class BuildBackendBase:
1520
def __init__(self, cwd='.', env={}, backend_name='setuptools.build_meta'):
1621
self.cwd = cwd
@@ -31,10 +36,23 @@ def __getattr__(self, name):
3136
def method(*args, **kw):
3237
root = os.path.abspath(self.cwd)
3338
caller = BuildBackendCaller(root, self.env, self.backend_name)
34-
return self.pool.submit(caller, name, *args, **kw).result()
39+
pid = None
40+
try:
41+
pid = self.pool.submit(os.getpid).result(TIMEOUT)
42+
return self.pool.submit(caller, name, *args, **kw).result(TIMEOUT)
43+
except futures.TimeoutError:
44+
self.pool.shutdown(wait=False) # doesn't stop already running processes
45+
self._kill(pid)
46+
pytest.xfail(f"Backend did not respond before timeout ({TIMEOUT} s)")
3547

3648
return method
3749

50+
def _kill(self, pid):
51+
if pid is None:
52+
return
53+
with contextlib.suppress(ProcessLookupError, OSError):
54+
os.kill(pid, signal.SIGTERM if os.name == "nt" else signal.SIGKILL)
55+
3856

3957
class BuildBackendCaller(BuildBackendBase):
4058
def __init__(self, *args, **kwargs):

tox.ini

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ usedevelop = True
1414
extras = testing
1515
passenv =
1616
SETUPTOOLS_USE_DISTUTILS
17+
TIMEOUT_BACKEND_TEST # timeout (in seconds) for test_build_meta
1718
windir # required for test_pkg_resources
1819
# honor git config in pytest-perf
1920
HOME

0 commit comments

Comments
 (0)