Exemplo n.º 1
0
def postgres_service(docker_services, docker_ip,
                     docker_compose_file) -> DataSourceName:

    # container environment
    with open(docker_compose_file) as fh:
        config = yaml.safe_load(fh)
    environ = config["services"]["postgres"]["environment"]

    dsn = DataSourceName(
        user=environ["POSTGRES_USER"],
        password=environ["POSTGRES_PASSWORD"],
        host=docker_ip,
        port=docker_services.port_for("postgres", 5432),
        database=environ["POSTGRES_DB"],
        application_name="test-app",
    )

    # Wait until service is responsive.
    docker_services.wait_until_responsive(
        check=lambda: is_postgres_responsive(dsn),
        timeout=30.0,
        pause=0.1,
    )
    return dsn
Exemplo n.º 2
0
async def wait_till_postgres_responsive(dsn: DataSourceName) -> None:
    if not is_postgres_responsive(dsn):
        raise Exception