2edb22bfbd
On the self-hosted KVM runner Docker is on PATH but the daemon socket is unreachable (firewalled/dropped). subprocess.run(["docker", "info"]) with no timeout hangs indefinitely on a dropped connection, stalling the coverage job for hours — one hang per @skip_unless_docker()-decorated class, ~8 per integration suite run. Add timeout=5 with a TimeoutExpired → False fallback so the check resolves quickly to "unreachable" rather than blocking.
30 lines
702 B
Python
30 lines
702 B
Python
"""Docker availability check used by integration tests."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import shutil
|
|
import subprocess
|
|
import unittest
|
|
|
|
|
|
def docker_available() -> bool:
|
|
if shutil.which("docker") is None:
|
|
return False
|
|
try:
|
|
return (
|
|
subprocess.run(
|
|
["docker", "info"],
|
|
stdout=subprocess.DEVNULL,
|
|
stderr=subprocess.DEVNULL,
|
|
check=False,
|
|
timeout=5,
|
|
).returncode
|
|
== 0
|
|
)
|
|
except subprocess.TimeoutExpired:
|
|
return False
|
|
|
|
|
|
def skip_unless_docker(reason: str = "docker unreachable"):
|
|
return unittest.skipUnless(docker_available(), reason)
|