|
| 1 | +import asyncio |
| 2 | +import os |
| 3 | +from datetime import timedelta |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from google.protobuf.duration import from_timedelta |
| 8 | +from pytest_docker import Services |
| 9 | + |
| 10 | +from cadence.api.v1.service_domain_pb2 import RegisterDomainRequest |
| 11 | +from cadence.client import ClientOptions |
| 12 | +from tests.conftest import ENABLE_INTEGRATION_TESTS |
| 13 | +from tests.integration_tests.helper import CadenceHelper, DOMAIN_NAME |
| 14 | + |
| 15 | +# Run tests in this directory and lower only if integration tests are enabled |
| 16 | +def pytest_runtest_setup(item): |
| 17 | + if not item.config.getoption(ENABLE_INTEGRATION_TESTS): |
| 18 | + pytest.skip(f"{ENABLE_INTEGRATION_TESTS} not enabled") |
| 19 | + |
| 20 | +@pytest.fixture(scope="session") |
| 21 | +def docker_compose_file(pytestconfig): |
| 22 | + return os.path.join(str(pytestconfig.rootdir), "tests", "integration_tests", "docker-compose.yml") |
| 23 | + |
| 24 | +@pytest.fixture(scope="session") |
| 25 | +def client_options(docker_ip: str, docker_services: Services) -> ClientOptions: |
| 26 | + return ClientOptions( |
| 27 | + domain=DOMAIN_NAME, |
| 28 | + target=f'{docker_ip}:{docker_services.port_for("cadence", 7833)}', |
| 29 | + ) |
| 30 | + |
| 31 | +# We can't pass around Client objects between tests/fixtures without changing our pytest-asyncio version |
| 32 | +# to ensure that they use the same event loop. |
| 33 | +# Instead, we can wait for the server to be ready, create the common domain, and then provide a helper capable |
| 34 | +# of creating additional clients within each test as needed |
| 35 | +@pytest.fixture(scope="session") |
| 36 | +async def helper(client_options: ClientOptions) -> CadenceHelper: |
| 37 | + helper = CadenceHelper(client_options) |
| 38 | + async with helper.client() as client: |
| 39 | + # It takes around a minute for the Cadence server to start up with Cassandra |
| 40 | + async with asyncio.timeout(120): |
| 41 | + await client.ready() |
| 42 | + |
| 43 | + await client.domain_stub.RegisterDomain(RegisterDomainRequest( |
| 44 | + name=DOMAIN_NAME, |
| 45 | + workflow_execution_retention_period=from_timedelta(timedelta(days=1)), |
| 46 | + )) |
| 47 | + return CadenceHelper(client_options) |
0 commit comments