|
| 1 | +import os |
| 2 | +import pytest |
| 3 | +import time |
| 4 | +import ydb |
| 5 | + |
| 6 | + |
| 7 | +@pytest.fixture(scope="module") |
| 8 | +def docker_compose_file(pytestconfig): |
| 9 | + return os.path.join(str(pytestconfig.rootdir), "docker-compose.yml") |
| 10 | + |
| 11 | + |
| 12 | +def wait_container_ready(driver): |
| 13 | + driver.wait(timeout=30) |
| 14 | + |
| 15 | + with ydb.SessionPool(driver) as pool: |
| 16 | + started_at = time.time() |
| 17 | + while time.time() - started_at < 30: |
| 18 | + try: |
| 19 | + with pool.checkout() as session: |
| 20 | + session.execute_scheme( |
| 21 | + "create table `.sys_health/test_table` " |
| 22 | + "(A int32, primary key(A));" |
| 23 | + ) |
| 24 | + |
| 25 | + return True |
| 26 | + |
| 27 | + except ydb.Error: |
| 28 | + time.sleep(1) |
| 29 | + |
| 30 | + raise RuntimeError("Container is not ready after timeout.") |
| 31 | + |
| 32 | + |
| 33 | +@pytest.fixture(scope="module") |
| 34 | +def endpoint(pytestconfig, module_scoped_container_getter): |
| 35 | + with ydb.Driver(endpoint="localhost:2136", database="/local") as driver: |
| 36 | + wait_container_ready(driver) |
| 37 | + yield "localhost:2136" |
| 38 | + |
| 39 | + |
| 40 | +@pytest.fixture(scope="module") |
| 41 | +def database(): |
| 42 | + return "/local" |
| 43 | + |
| 44 | + |
| 45 | +@pytest.fixture() |
| 46 | +async def driver(endpoint, database, event_loop): |
| 47 | + driver_config = ydb.DriverConfig( |
| 48 | + endpoint, |
| 49 | + database, |
| 50 | + ) |
| 51 | + |
| 52 | + driver = ydb.aio.Driver(driver_config=driver_config) |
| 53 | + await driver.wait(timeout=15) |
| 54 | + |
| 55 | + yield driver |
| 56 | + |
| 57 | + await driver.stop(timeout=10) |
0 commit comments