Skip to content

Commit

Permalink
dev: use pg_tmp instead of some non-official fork of testing.postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
em92 committed Mar 9, 2024
1 parent 3057078 commit bd7af0f
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 26 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: 9.5
- 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
7 changes: 7 additions & 0 deletions Dockerfile.develop.alt10
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile.develop.bookworm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile.develop.bullseye
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile.develop.buster
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile.develop.focal
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile.develop.jammy
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile.develop.noble
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 8 additions & 2 deletions Dockerfile.develop.sisyphus
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile.develop.trixie
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 19 additions & 22 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit bd7af0f

Please sign in to comment.