Fix integration test race condition by isolating PlatformIO directories (#9383)

This commit is contained in:
J. Nick Koston 2025-07-07 23:34:39 -05:00 committed by GitHub
parent 4648804db6
commit a30f01d668
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -165,6 +165,19 @@ async def compile_esphome(
"""Compile an ESPHome configuration and return the binary path."""
async def _compile(config_path: Path) -> Path:
# Create a unique PlatformIO directory for this test to avoid race conditions
platformio_dir = integration_test_dir / ".platformio"
platformio_dir.mkdir(parents=True, exist_ok=True)
# Create cache directory as well
platformio_cache_dir = platformio_dir / ".cache"
platformio_cache_dir.mkdir(parents=True, exist_ok=True)
# Set up environment with isolated PlatformIO directories
env = os.environ.copy()
env["PLATFORMIO_CORE_DIR"] = str(platformio_dir)
env["PLATFORMIO_CACHE_DIR"] = str(platformio_cache_dir)
# Retry compilation up to 3 times if we get a segfault
max_retries = 3
for attempt in range(max_retries):
@ -179,6 +192,7 @@ async def compile_esphome(
stdin=asyncio.subprocess.DEVNULL,
# Start in a new process group to isolate signal handling
start_new_session=True,
env=env,
)
await proc.wait()