Skip to content

[maintenance] improve stability of deploy tests #1563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# pylint:disable=unused-variable
# pylint:disable=unused-argument
# pylint:disable=redefined-outer-name

from typing import Dict

import aiohttp
import pytest
import tenacity
from yarl import URL

from servicelib.minio_utils import MinioRetryPolicyUponInitialization

from .helpers.utils_docker import get_service_published_port


@pytest.fixture(scope="module")
def webserver_endpoint(docker_stack: Dict, devel_environ: Dict) -> URL:
assert "simcore_webserver" in docker_stack["services"]
endpoint = f"127.0.0.1:{get_service_published_port('webserver', '8080')}"

return URL(f"http://{endpoint}")


@pytest.fixture(scope="function")
async def webserver_service(webserver_endpoint: URL, docker_stack: Dict) -> URL:
await wait_till_webserver_responsive(webserver_endpoint)

yield webserver_endpoint


# HELPERS --

# TODO: this can be used by ANY of the simcore services!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this is reusable :-)

@tenacity.retry(**MinioRetryPolicyUponInitialization().kwargs)
async def wait_till_webserver_responsive(webserver_endpoint: URL):
async with aiohttp.ClientSession() as session:
async with session.get(webserver_endpoint.with_path("/v0/")) as resp:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are going to have one day troubles with the AIP versions ... I start putting them as separate fixtures as well

assert resp.status == 200
data = await resp.json()
assert "data" in data
assert "status" in data["data"]
assert data["data"]["status"] == "SERVICE_RUNNING"
9 changes: 8 additions & 1 deletion tests/swarm-deploy/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"pytest_simcore.rabbit_service",
"pytest_simcore.postgres_service",
"pytest_simcore.minio_service",
"pytest_simcore.traefik_service"
"pytest_simcore.traefik_service",
"pytest_simcore.simcore_webserver_service",
]
log = logging.getLogger(__name__)

Expand All @@ -44,8 +45,14 @@ def prepare_all_services(
return services


@pytest.fixture(scope="module")
def create_db_on_start(devel_environ: Dict[str, str]):
devel_environ["WEBSERVER_DB_INITTABLES"] = "1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change this in another pR by migration routings ... but it is ok for now :-)



@pytest.fixture(scope="module")
def make_up_prod(
create_db_on_start,
prepare_all_services: Dict,
simcore_docker_compose: Dict,
ops_docker_compose: Dict,
Expand Down
18 changes: 17 additions & 1 deletion tests/swarm-deploy/test_swarm_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from typing import Dict, List

import pytest
import tenacity
from docker import DockerClient
from docker.models.services import Service
from yarl import URL
Expand Down Expand Up @@ -146,10 +147,25 @@ def test_core_service_running(
)


RETRY_WAIT_SECS = 2
RETRY_COUNT = 20


def test_check_serve_root(loop, make_up_prod: Dict, traefik_service: URL):

req = urllib.request.Request("http://127.0.0.1:9081/")
try:
resp = urllib.request.urlopen(req)
# it takes a bit of time until traefik sets up the correct proxy and the webserver takes time to start
@tenacity.retry(
wait=tenacity.wait_fixed(RETRY_WAIT_SECS),
stop=tenacity.stop_after_attempt(RETRY_COUNT),
before_sleep=tenacity.before_sleep_log(logger, logging.INFO),
)
def check_root(request):
resp = urllib.request.urlopen(req)
return resp

resp = check_root(req)
charset = resp.info().get_content_charset()
content = resp.read().decode(charset)
# TODO: serch osparc-simcore commit id e.g. 'osparc-simcore v817d82e'
Expand Down