Skip to content

Commit

Permalink
tests: Replace "localhost" domain name with the equivalent IPv4 address
Browse files Browse the repository at this point in the history
It's common that "localhost" translates with both IPv4 and IPv6. The
simple containerized test PyPI server we use in our CI doesn't listen
on IPv6 which may cause unpredictable issues on hosts where IPv6 is
enabled and IPv6 would get prioritized by the low level network stack
connection primitives. Therefore, use an IP explicitly to avoid any
potential issues during pytest run, e.g.:

    DEBUG Starting new HTTP connection (1): localhost:8080
    DEBUG ('Connection aborted.',
           ConnectionResetError(104, 'Connection reset by peer'))

Signed-off-by: Erik Skultety <[email protected]>
  • Loading branch information
eskultety committed Oct 7, 2024
1 parent 93915e7 commit b289c91
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import pytest
import requests

from tests.integration.utils import TEST_SERVER_LOCALHOST

from . import utils

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -59,7 +61,7 @@ def local_pypiserver() -> Iterator[None]:
for _ in range(60):
time.sleep(1)
try:
resp = requests.get(f"http://localhost:{pypiserver_port}")
resp = requests.get(f"http://{TEST_SERVER_LOCALHOST}:{pypiserver_port}")
resp.raise_for_status()
log.debug(resp.text)
break
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_data/pip_custom_index/bom.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"value": "cachi2"
}
],
"purl": "pkg:pypi/cachi2-pip-custom-index?vcs_url=git%2Bhttps://github.com/cachito-testing/cachi2-pip-custom-index.git%404d6fe87e62b984cf420e6c8377821a76895b72a8",
"purl": "pkg:pypi/cachi2-pip-custom-index?vcs_url=git%2Bhttps://github.com/cachito-testing/cachi2-pip-custom-index.git%4055376bc13904c2f450aac6ee89969d539c8d9f05",
"type": "library"
},
{
Expand All @@ -24,7 +24,7 @@
"value": "true"
}
],
"purl": "pkg:pypi/[email protected]?repository_url=http://localhost:8080/simple/",
"purl": "pkg:pypi/[email protected]?repository_url=http://127.0.0.1:8080/simple/",
"type": "library",
"version": "2.32.3"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
pytest.param(
utils.TestParameters(
repo="https://github.com/cachito-testing/cachi2-pip-custom-index.git",
ref="4d6fe87e62b984cf420e6c8377821a76895b72a8",
ref="55376bc13904c2f450aac6ee89969d539c8d9f05",
packages=({"path": ".", "type": "pip", "allow_binary": True},),
check_vendor_checksums=False,
expected_exit_code=0,
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

from cachi2.core import resolver

# force IPv4 localhost as 'localhost' can resolve with IPv6 as well
TEST_SERVER_LOCALHOST = "127.0.0.1"

# Individual files could be added to the set as well.
PATHS_TO_CODE = frozenset((Path("cachi2"), Path("tests/integration")))
SUPPORTED_PMS: frozenset[str] = frozenset(
Expand Down
2 changes: 1 addition & 1 deletion tests/pypiserver/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ setup() {
ls -lA "$WORKDIR/auth"
tar cf - -C "$WORKDIR/auth" . | podman volume import cachi2-pypiserver-auth -

echo -e "\n--- Starting pypiserver on http://localhost:${PYPISERVER_PORT:-8080} ---\n"
echo -e "\n--- Starting pypiserver on http://127.0.0.1:${PYPISERVER_PORT:-8080} ---\n"
}

setup >&2
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ passenv =
PYPISERVER_IMAGE
PYPISERVER_PORT
setenv =
CACHI2_TEST_NETRC_CONTENT={env:CACHI2_TEST_NETRC_CONTENT:machine localhost login cachi2-user password cachi2-pass}
CACHI2_TEST_NETRC_CONTENT={env:CACHI2_TEST_NETRC_CONTENT:machine 127.0.0.1 login cachi2-user password cachi2-pass}
basepython = python3
skip_install = true
commands =
Expand Down

0 comments on commit b289c91

Please sign in to comment.