From d2e0ec917253f792b17e7959e9fd4f955c544599 Mon Sep 17 00:00:00 2001 From: Eugene Molotov Date: Sat, 9 Mar 2024 18:40:16 +0500 Subject: [PATCH] dev: use pg_tmp instead of some non-official fork of testing.postgresql --- .github/workflows/build.yml | 9 +++++++- Dockerfile.develop.alt10 | 7 +++++++ Dockerfile.develop.bookworm | 7 +++++++ Dockerfile.develop.bullseye | 7 +++++++ Dockerfile.develop.buster | 7 +++++++ Dockerfile.develop.focal | 7 +++++++ Dockerfile.develop.jammy | 7 +++++++ Dockerfile.develop.noble | 7 +++++++ Dockerfile.develop.sisyphus | 10 +++++++-- Dockerfile.develop.trixie | 7 +++++++ requirements_dev.txt | 1 - tests/conftest.py | 41 +++++++++++++++++-------------------- 12 files changed, 91 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a6f4dd0..d4f6c06 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,7 +33,14 @@ jobs: - name: Install development requirements run: python3 -m pip install -r requirements_dev.txt - name: Install postgresql - run: sudo apt-get install postgresql + uses: tj-actions/install-postgresql@v3 + with: + postgresql-version: 11 + - name: Install pg_tmp + run: | + sudo apt-get install build-essential + git clone https://github.com/eradman/ephemeralpg.git + cd ephemeralpg && make && sudo make install - name: Test run: ./scripts/test - uses: codecov/codecov-action@v1 diff --git a/Dockerfile.develop.alt10 b/Dockerfile.develop.alt10 index 677592e..bb3c1b4 100644 --- a/Dockerfile.develop.alt10 +++ b/Dockerfile.develop.alt10 @@ -13,11 +13,18 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y \ + gcc make \ git \ postgresql15-server \ python3-modules-sqlite3 \ && find /var/lib/apt/lists/ -type f -delete +RUN git clone https://github.com/eradman/ephemeralpg.git \ + && cd ephemeralpg \ + && make && make install \ + && cd .. \ + && rm -rf ephemeralpg/ + ENV PATH="/usr/lib/postgresql/15/bin:${PATH}" # take out coverage report from source directory ENV COVERAGE_FILE="/tmp/qllr.coverage" diff --git a/Dockerfile.develop.bookworm b/Dockerfile.develop.bookworm index e4233f0..a0f4d51 100644 --- a/Dockerfile.develop.bookworm +++ b/Dockerfile.develop.bookworm @@ -13,10 +13,17 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + build-essential \ git \ postgresql-15 \ && rm -rf /var/lib/apt/lists/* +RUN git clone https://github.com/eradman/ephemeralpg.git \ + && cd ephemeralpg \ + && make && make install \ + && cd .. \ + && rm -rf ephemeralpg/ + ENV PATH="/usr/lib/postgresql/15/bin:${PATH}" # take out coverage report from source directory ENV COVERAGE_FILE="/tmp/qllr.coverage" diff --git a/Dockerfile.develop.bullseye b/Dockerfile.develop.bullseye index 91704f0..efe7386 100644 --- a/Dockerfile.develop.bullseye +++ b/Dockerfile.develop.bullseye @@ -13,10 +13,17 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + build-essential \ git \ postgresql-13 \ && rm -rf /var/lib/apt/lists/* +RUN git clone https://github.com/eradman/ephemeralpg.git \ + && cd ephemeralpg \ + && make && make install \ + && cd .. \ + && rm -rf ephemeralpg/ + ENV PATH="/usr/lib/postgresql/13/bin:${PATH}" # take out coverage report from source directory ENV COVERAGE_FILE="/tmp/qllr.coverage" diff --git a/Dockerfile.develop.buster b/Dockerfile.develop.buster index b6c629c..ece17d2 100644 --- a/Dockerfile.develop.buster +++ b/Dockerfile.develop.buster @@ -16,10 +16,17 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + build-essential \ git \ postgresql-11 \ && rm -rf /var/lib/apt/lists/* +RUN git clone https://github.com/eradman/ephemeralpg.git \ + && cd ephemeralpg \ + && make && make install \ + && cd .. \ + && rm -rf ephemeralpg/ + ENV PATH="/usr/lib/postgresql/11/bin:${PATH}" # take out coverage report from source directory ENV COVERAGE_FILE="/tmp/qllr.coverage" diff --git a/Dockerfile.develop.focal b/Dockerfile.develop.focal index 9d0108c..17e6a4c 100644 --- a/Dockerfile.develop.focal +++ b/Dockerfile.develop.focal @@ -15,10 +15,17 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + build-essential \ git \ postgresql-12 \ && rm -rf /var/lib/apt/lists/* +RUN git clone https://github.com/eradman/ephemeralpg.git \ + && cd ephemeralpg \ + && make && make install \ + && cd .. \ + && rm -rf ephemeralpg/ + ENV PATH="/usr/lib/postgresql/12/bin:${PATH}" # take out coverage report from source directory ENV COVERAGE_FILE="/tmp/qllr.coverage" diff --git a/Dockerfile.develop.jammy b/Dockerfile.develop.jammy index 3a90aa5..45a2e50 100644 --- a/Dockerfile.develop.jammy +++ b/Dockerfile.develop.jammy @@ -13,10 +13,17 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + build-essential \ git \ postgresql-14 \ && rm -rf /var/lib/apt/lists/* +RUN git clone https://github.com/eradman/ephemeralpg.git \ + && cd ephemeralpg \ + && make && make install \ + && cd .. \ + && rm -rf ephemeralpg/ + ENV PATH="/usr/lib/postgresql/14/bin:${PATH}" # take out coverage report from source directory ENV COVERAGE_FILE="/tmp/qllr.coverage" diff --git a/Dockerfile.develop.noble b/Dockerfile.develop.noble index d9de119..1f95075 100644 --- a/Dockerfile.develop.noble +++ b/Dockerfile.develop.noble @@ -13,10 +13,17 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + build-essential \ git \ postgresql-16 \ && rm -rf /var/lib/apt/lists/* +RUN git clone https://github.com/eradman/ephemeralpg.git \ + && cd ephemeralpg \ + && make && make install \ + && cd .. \ + && rm -rf ephemeralpg/ + ENV PATH="/usr/lib/postgresql/16/bin:${PATH}" # take out coverage report from source directory ENV COVERAGE_FILE="/tmp/qllr.coverage" diff --git a/Dockerfile.develop.sisyphus b/Dockerfile.develop.sisyphus index 63899d5..47ad944 100644 --- a/Dockerfile.develop.sisyphus +++ b/Dockerfile.develop.sisyphus @@ -11,13 +11,19 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ python3-module-uvicorn \ && find /var/lib/apt/lists/ -type f -delete -RUN apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y \ +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ + build-essential \ git \ postgresql15-server \ python3-modules-sqlite3 \ && find /var/lib/apt/lists/ -type f -delete +RUN git clone https://github.com/eradman/ephemeralpg.git \ + && cd ephemeralpg \ + && make && make install \ + && cd .. \ + && rm -rf ephemeralpg/ + ENV PATH="/usr/lib/postgresql/15/bin:${PATH}" # take out coverage report from source directory ENV COVERAGE_FILE="/tmp/qllr.coverage" diff --git a/Dockerfile.develop.trixie b/Dockerfile.develop.trixie index 3021b79..9dc5e05 100644 --- a/Dockerfile.develop.trixie +++ b/Dockerfile.develop.trixie @@ -13,10 +13,17 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + build-essential \ git \ postgresql-16 \ && rm -rf /var/lib/apt/lists/* +RUN git clone https://github.com/eradman/ephemeralpg.git \ + && cd ephemeralpg \ + && make && make install \ + && cd .. \ + && rm -rf ephemeralpg/ + ENV PATH="/usr/lib/postgresql/16/bin:${PATH}" # take out coverage report from source directory ENV COVERAGE_FILE="/tmp/qllr.coverage" diff --git a/requirements_dev.txt b/requirements_dev.txt index 2f61f1c..4bcf5a7 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -2,7 +2,6 @@ pytest==5.4.3; python_version < '3.10' pytest==6.2.5; python_version >= '3.10' pytest-asyncio==0.11.0 pytest-cov -git+https://github.com/BrandonNav/testing.postgresql@f849c786eaa9d2c0ff8b2a5f3fb21e96742ec8b6 pylint flake8 httpx diff --git a/tests/conftest.py b/tests/conftest.py index 72f7c18..1889979 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,36 +8,33 @@ from requests import Response from starlette.config import environ from starlette.testclient import TestClient -from testing import postgresql as pgsql_test +from subprocess import check_output + -postgresql = None module_path = os.path.dirname(os.path.realpath(__file__)) def pytest_configure(config): - def handler(postgresql): - f = open(os.path.dirname(os.path.realpath(__file__)) + "/../sql/init.sql") - sql_query = f.read() - f.close() - conn = psycopg2.connect(**postgresql.dsn()) - cursor = conn.cursor() - cursor.execute(sql_query) - cursor.close() - conn.commit() - conn.close() - - global postgresql - # force default timezone to pass tests on os with different local timezone setting - pgsql_test.Postgresql.DEFAULT_SETTINGS["postgres_args"] += " -c timezone=+5" + environ["USE_AVG_PERF_TDM"] = "TRUE" + environ["CACHE_HTTP_RESPONSE"] = "1" + environ["DATABASE_URL"] = check_output(["pg_tmp", "-t"]).decode("utf-8") - PGSQLFactory = pgsql_test.PostgresqlFactory( - cache_initialized_db=True, on_initialized=handler + # force default timezone to pass tests on os with different local timezone setting + data_dir = ( + check_output( + ["psql", environ["DATABASE_URL"], "-At", "-c", "SHOW data_directory"] + ) + .decode("utf-8") + .strip() ) + with open(data_dir + "/postgresql.conf", "a") as f: + f.write("timezone = +5\n") + check_output(["psql", environ["DATABASE_URL"], "-c", "select pg_reload_conf()"]) - postgresql = PGSQLFactory() - environ["DATABASE_URL"] = postgresql.url() - environ["USE_AVG_PERF_TDM"] = "TRUE" - environ["CACHE_HTTP_RESPONSE"] = "1" + # create tables + check_output( + ["psql", environ["DATABASE_URL"], "-f", module_path + "/../sql/init.sql"] + ) def read_sample(sample_filename: str) -> str: