Skip to content

Commit 6dbdce8

Browse files
committed
Fix grpclib-ttrpc AF_UNIX socket path too long error in Nix builds
Use /tmp for socket paths instead of pytest's tmp_path fixture, which becomes very long in Nix store context and exceeds the 108-byte Unix socket path limit. Changes: - test_functional.py: unix_server fixture uses /tmp/ttrpc_test_{pid}.sock - conftest.py: socket_path fixture uses /tmp/ttrpc_{pid}.sock with cleanup - Both fixtures use PID-based unique names to avoid socket collisions - Added proper cleanup logic to remove stale socket files All tests now pass in Nix build context.
1 parent 8219df1 commit 6dbdce8

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

pkgs/grpclib-ttrpc/tests/conftest.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import os
77
import sys
88
from pathlib import Path
9-
from typing import AsyncGenerator
9+
from typing import AsyncGenerator, Generator
1010

1111
import pytest
1212
import pytest_asyncio
@@ -32,9 +32,26 @@ def test_server_bin() -> Path:
3232

3333

3434
@pytest.fixture
35-
def socket_path(tmp_path: Path) -> Path:
36-
"""Create a unique socket path for each test."""
37-
return tmp_path / "ttrpc.sock"
35+
def socket_path() -> Generator[Path, None, None]:
36+
"""Create a unique socket path for each test.
37+
38+
Uses /tmp to avoid "AF_UNIX path too long" error when running in Nix build
39+
(pytest's tmp_path is too deep in the Nix store, exceeding 108-byte limit).
40+
"""
41+
path = Path(f"/tmp/ttrpc_{os.getpid()}.sock")
42+
# Clean up any stale socket file from previous runs
43+
try:
44+
if path.exists():
45+
path.unlink()
46+
except OSError:
47+
pass
48+
yield path
49+
# Clean up after the test
50+
try:
51+
if path.exists():
52+
path.unlink()
53+
except OSError:
54+
pass
3855

3956

4057
@pytest_asyncio.fixture

pkgs/grpclib-ttrpc/tests/test_functional.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""End-to-end functional tests for grpclib_ttrpc.Server."""
22

33
import asyncio
4+
import os
45
from typing import cast
56

67
import pytest
@@ -56,8 +57,10 @@ async def tcp_client(tcp_server):
5657

5758

5859
@pytest_asyncio.fixture
59-
async def unix_server(tmp_path):
60-
sock_path = str(tmp_path / "ttrpc_test.sock")
60+
async def unix_server():
61+
# Use /tmp to avoid "AF_UNIX path too long" error when running in Nix build
62+
# (pytest's tmp_path is too deep in the Nix store, exceeding 108-byte limit)
63+
sock_path = f"/tmp/ttrpc_test_{os.getpid()}.sock"
6164
svc = DummyServiceImpl()
6265
server = Server([svc])
6366
await server.start(path=sock_path)

0 commit comments

Comments
 (0)