Skip to content

Commit

Permalink
unused port and ip
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed May 4, 2023
1 parent d48c9e1 commit 024927b
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/pytest-simcore/src/pytest_simcore/httpbin_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,36 @@
from contextlib import suppress
from typing import Iterable

import aiohttp.test_utils
import docker
import pytest
import requests
import requests.exceptions
from docker.errors import APIError
from pydantic import HttpUrl
from pydantic import HttpUrl, parse_obj_as
from tenacity import retry
from tenacity.after import after_log
from tenacity.retry import retry_if_exception_type
from tenacity.stop import stop_after_delay
from tenacity.wait import wait_fixed

from .helpers.utils_docker import get_localhost_ip


@pytest.fixture(scope="session")
def httpbin_base_url() -> Iterable[HttpUrl]:
"""Implemented since https://httpbin.org/ is not always available"""

port = 80
base_url = f"http://127.0.0.1:{port}"
"""
Implemented cannot rely on https://httpbin.org/ being always available
"""
ip_address = get_localhost_ip()
port = aiohttp.test_utils.unused_port()
base_url = f"http://{ip_address}:{port}"

client = docker.from_env()
container_name = "httpbin-fixture"
try:
client.containers.run(
"kennethreitz/httpbin",
image="kennethreitz/httpbin",
ports={port: 80},
name=container_name,
detach=True,
Expand All @@ -45,7 +50,7 @@ def httpbin_base_url() -> Iterable[HttpUrl]:
after=after_log(logging.getLogger(), logging.DEBUG),
)
def _wait_until_httpbin_is_responsive():
r = requests.get(f"{base_url}/get")
r = requests.get(f"{base_url}/get", timeout=2)
r.raise_for_status()

_wait_until_httpbin_is_responsive()
Expand Down

0 comments on commit 024927b

Please sign in to comment.