diff --git a/.travis.yml b/.travis.yml index 8a74f94b..f601680f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,10 +3,10 @@ language: python python: 3.8 install: -- pip3 install sqlalchemy +- pip3 install -r requirements.txt script: -- make test +- make all branches: except: diff --git a/conftest.py b/conftest.py index f43dd114..da82d88a 100644 --- a/conftest.py +++ b/conftest.py @@ -3,11 +3,14 @@ from pathlib import Path import pytest +import requests +from requests.exceptions import ConnectionError +from sqlalchemy.exc import OperationalError from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker, clear_mappers from orm import metadata, start_mappers -from config import get_postgres_uri +import config @pytest.fixture @@ -24,9 +27,31 @@ def session(in_memory_db): clear_mappers() +def wait_for_postgres_to_come_up(engine): + deadline = time.time() + 10 + while time.time() < deadline: + try: + return engine.connect() + except OperationalError: + time.sleep(0.5) + pytest.fail("Postgres never came up") + + +def wait_for_webapp_to_come_up(): + deadline = time.time() + 10 + url = config.get_api_url() + while time.time() < deadline: + try: + return requests.get(url) + except ConnectionError: + time.sleep(0.5) + pytest.fail("API never came up") + + @pytest.fixture(scope="session") def postgres_db(): - engine = create_engine(get_postgres_uri()) + engine = create_engine(config.get_postgres_uri()) + wait_for_postgres_to_come_up(engine) metadata.create_all(engine) return engine @@ -78,4 +103,5 @@ def _add_stock(lines): @pytest.fixture def restart_api(): (Path(__file__).parent / "flask_app.py").touch() - time.sleep(0.3) + time.sleep(0.5) + wait_for_webapp_to_come_up()