Skip to content

Commit

Permalink
ADCM-6290 Allow running tests in parallel (#86)
Browse files Browse the repository at this point in the history
Co-authored-by: Araslanov Egor <[email protected]>
  • Loading branch information
2 people authored and a-alferov committed Jan 24, 2025
1 parent 5c0319c commit 7e12323
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 49 deletions.
73 changes: 70 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ testcontainers = "^4.8.2"
pyyaml = "^6.0.2"
pytest-timeout = "^2.3.1"
docker = "^7.1.0"
pytest-xdist = "^3.6.1"

[build-system]
requires = ["poetry-core"]
Expand Down
46 changes: 9 additions & 37 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections.abc import AsyncGenerator, Generator
from io import BytesIO
from pathlib import Path
from time import sleep
from urllib.parse import urljoin
import os
import random
Expand All @@ -10,7 +9,6 @@

from httpx import AsyncClient
from testcontainers.core.network import Network
import httpx
import pytest
import pytest_asyncio

Expand All @@ -34,35 +32,6 @@
################


def load_certs_to_running_adcm(adcm: ADCMContainer, certs_dir: Path) -> None:
file = BytesIO()
with tarfile.open(mode="w:gz", fileobj=file) as tar:
tar.add(certs_dir, "")
file.seek(0)

container = adcm.get_wrapped_container()
container.put_archive("/adcm/data/conf/ssl", file.read())
ec, out = adcm.exec(["nginx", "-s", "reload"])
if ec != 0:
raise RuntimeError(f"Failed to reload nginx after attaching certs: {out.decode('utf-8')}")

verify_cert_path = str(certs_dir / "cert.pem")

attempts = 15
last_err = None

for _ in range(attempts):
try:
httpx.get(adcm.ssl_url, verify=verify_cert_path)
except httpx.ConnectError as e:
last_err = e
sleep(0.1)
else:
return

raise RuntimeError(f"Failed to connect to HTTPS port with {attempts} attempts") from last_err


@pytest.fixture(scope="session")
def network() -> Generator[Network, None, None]:
with Network() as network:
Expand Down Expand Up @@ -102,12 +71,13 @@ def adcm_image(network: Network, postgres: ADCMPostgresContainer, ssl_certs_dir:
db = DatabaseInfo(name=f"adcm_{suffix}_migration", host=postgres.name)
postgres.execute_statement(f"CREATE DATABASE {db.name} OWNER {DB_USER}")

with ADCMContainer(image=f"{base_repo}:{base_tag}", network=network, db=db, migration_mode=True) as adcm:
file = BytesIO()
with tarfile.open(mode="w:gz", fileobj=file) as tar:
tar.add(ssl_certs_dir, "")
file.seek(0)
file = BytesIO()
with tarfile.open(mode="w:gz", fileobj=file) as tar:
tar.add(ssl_certs_dir, "")
file.seek(0)
adcm = ADCMContainer(image=f"{base_repo}:{base_tag}", network=network, db=db, migration_mode=True)

with adcm:
container = adcm.get_wrapped_container()
container.put_archive("/adcm/data/conf/ssl", file.read())
container.commit(repository=new_repo, tag=new_tag)
Expand All @@ -121,7 +91,9 @@ def adcm(network: Network, postgres: ADCMPostgresContainer, adcm_image: str) ->
db = DatabaseInfo(name=f"adcm_{suffix}", host=postgres.name)
postgres.execute_statement(f"CREATE DATABASE {db.name} OWNER {DB_USER}")

with ADCMContainer(image=adcm_image, network=network, db=db) as container:
adcm = ADCMContainer(image=adcm_image, network=network, db=db)

with adcm as container:
yield container

postgres.execute_statement(f"DROP DATABASE {db.name}")
Expand Down
Loading

0 comments on commit 7e12323

Please sign in to comment.