From 96c8a54154134015403f2fd81959f52fd755fcac Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Wed, 28 Oct 2026 18:09:06 -0700 Subject: [PATCH] test(unit): fall back to /tmp when TMPDIR leaves no room for a socket path socket_dir now uses /tmp when TMPDIR plus the longest socket suffix would pass macOS's sun_path limit, and its teardown ignores errors so a failed test reports only its own failure --- tests/unit/conftest.py | 13 +++++++++++-- tests/unit/proxy/conftest.py | 1 - 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index 045888ee1f5..846758beb5c 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -219,12 +219,21 @@ def _flush_client_caches() -> None: _reset_aws_auth_caches() +_MACOS_LONGEST_SOCKET_PATH: Final = 103 +_LONGEST_SOCKET_SUFFIX: Final = len("/sock12345678/.s.PGSQL.65535") + + +def _socket_root() -> str: + default: Final = tempfile.gettempdir() + return default if len(default) + _LONGEST_SOCKET_SUFFIX <= _MACOS_LONGEST_SOCKET_PATH else "/tmp" + + @pytest.fixture def socket_dir() -> Iterator[Path]: """A directory whose unix socket paths fit the kernel's sun_path limit, which pytest's tmp_path exceeds on macOS.""" - directory: Final = Path(tempfile.mkdtemp(prefix="sock")) + directory: Final = Path(tempfile.mkdtemp(prefix="sock", dir=_socket_root())) yield directory - shutil.rmtree(directory) + shutil.rmtree(directory, ignore_errors=True) @pytest.fixture diff --git a/tests/unit/proxy/conftest.py b/tests/unit/proxy/conftest.py index e026a2d0c3a..e13eddef43b 100644 --- a/tests/unit/proxy/conftest.py +++ b/tests/unit/proxy/conftest.py @@ -8,7 +8,6 @@ import os import tempfile import warnings from collections.abc import Awaitable, Callable, Iterator -from pathlib import Path from typing import Dict, Final, Optional from unittest.mock import AsyncMock, MagicMock, patch