fix(tests): pin the Postgres container URL to IPv4 so asyncpg can connect

Testcontainers reports the container host as `localhost`, which resolves
to ::1 before 127.0.0.1 on this machine. Docker publishes the mapped port
on IPv4 only, and the IPv6 SYN is dropped rather than refused, so asyncpg
blocked on the first address until its connect timeout instead of falling
back to the second -- the migration fixture hung rather than failing.

127.0.0.1 connects in 0.07s where localhost timed out at 15s; the
integration suite now runs in 3.6s, inside the 10s pytest-timeout.
This commit is contained in:
2026-08-18 10:40:32 +03:30
parent 5cdfb70085
commit 7753651dd6

View File

@@ -36,7 +36,15 @@ def postgres_container() -> Iterator[PostgresContainer]:
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def postgres_url(postgres_container: PostgresContainer) -> str: def postgres_url(postgres_container: PostgresContainer) -> str:
return postgres_container.get_connection_url() """The container's URL, pinned to IPv4.
Testcontainers reports the host as `localhost`, which resolves to `::1`
before `127.0.0.1`. Docker publishes the mapped port on IPv4 only, and the
IPv6 SYN is dropped rather than refused, so asyncpg blocks on the first
address until its connect timeout instead of falling back to the second --
the connection does not fail, it hangs.
"""
return postgres_container.get_connection_url().replace("@localhost:", "@127.0.0.1:")
@pytest.fixture(scope="session") @pytest.fixture(scope="session")