Skip to content

Commit b5dbb5c

Browse files
authored
Automatically detect whether we should run the postgres tests (#114)
This makes the developer experience smoother and will increase our test coverage for Postgres. Also ensure that we keep testing without Postgres installed, to ensure we don't start depending on Postgres being present on the client side. Finally, fix the Postgres-specific test that was failing due to the --xlogdir argument of `postgres` having been renamed.
1 parent 388d187 commit b5dbb5c

File tree

6 files changed

+23
-17
lines changed

6 files changed

+23
-17
lines changed

.github/workflows/tox.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ on:
77
jobs:
88
build:
99
runs-on: ubuntu-latest
10+
name: "Python ${{ matrix.python-version }}, Postgres=${{ matrix.with-postgres }}"
1011

1112
strategy:
1213
matrix:
1314
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
15+
with-postgres: [true, false]
1416
fail-fast: false
1517

1618
steps:
@@ -25,6 +27,11 @@ jobs:
2527
run: |
2628
python -m pip install --upgrade pip
2729
pip install tox tox-gh-actions
30+
- name: Install PostgreSQL
31+
if: ${{ matrix.with-postgres }}
32+
uses: tj-actions/install-postgresql@v3
33+
with:
34+
postgresql-version: 17
2835
- name: Tox flake8
2936
run: tox -e flake8
3037
- name: Tox docs

docs/developer_guide.rst

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ Optional Tests
5151
Some tests require additional tools to be installed and are not enabled by
5252
default. You can enable them by passing additional flags to ``lit``:
5353

54-
``-Dpostgres=1``
55-
Enable postgres database support testing. This requires at least
56-
postgres version 9.2 and the ``initdb`` and ``postgres`` binaries in your path.
57-
Note that you do not need to setup an actual server, the tests will create
58-
temporary instances on demand.
59-
6054
``-Dmysql=1``
6155
Enable mysql database support testing. This requires MySQL-python to be
6256
installed and expects the ``mysqld`` and ``mysqladmin`` binaries in your path.
@@ -74,7 +68,7 @@ default. You can enable them by passing additional flags to ``lit``:
7468

7569
Example::
7670

77-
lit -sv -Dpostgres=1 -Dmysql=1 -Dtidylib=1 ./tests
71+
lit -sv -Dmysql=1 -Dtidylib=1 ./tests
7872

7973
Publishing a new version of LNT
8074
-------------------------------

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ dev = [
6666
"filecheck",
6767
"Flake8-pyproject",
6868
"flake8",
69+
"gunicorn>=19.9.0",
6970
"lit",
71+
"psycopg2>=2.9.0",
7072
"tox",
7173
"twine",
7274
]
@@ -120,7 +122,7 @@ allowlist_externals = ["rm", "lit"]
120122
deps = [".[dev]"]
121123
commands = [
122124
["rm", "-rf", "test_run_tmp"],
123-
["lit", "-sv", "tests"],
125+
["lit", "-sv", "--show-unsupported", "tests"],
124126
]
125127

126128
[tool.tox.env.flake8]

tests/SharedInputs/postgres_wrapper.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22
# Setup minimalistic postgres instance in specified directory, start a server,
33
# run the given command and shutdown the server. Use
44
# `postgresql://pgtest@localhost:9100` to connect to the server.
@@ -10,7 +10,7 @@
1010
set -u
1111
TEST_DIR=$1
1212
shift
13-
DB_DIR="$(mktemp -d -t lnt)"
13+
DB_DIR="$(mktemp -d -t lnt.XXXXX)"
1414
if [ -d "${TEST_DIR}" ]; then
1515
echo 1>&2 "${TEST_DIR} already exists"
1616
exit 1
@@ -19,15 +19,17 @@ fi
1919
mkdir -p "${TEST_DIR}"
2020
ln -s ${TEST_DIR}/db_root ${DB_DIR}
2121

22+
INITDB_FLAGS=""
2223
INITDB_FLAGS+=" --pgdata=${DB_DIR}/db"
23-
INITDB_FLAGS+=" --xlogdir=${DB_DIR}/db"
24+
INITDB_FLAGS+=" --waldir=${DB_DIR}/db"
2425
INITDB_FLAGS+=" --nosync"
2526
INITDB_FLAGS+=" --no-locale"
2627
INITDB_FLAGS+=" --auth=trust"
2728
INITDB_FLAGS+=" --username=pgtest"
2829
echo "$ initdb $INITDB_FLAGS >& ${DB_DIR}/initdb_log.txt"
2930
initdb ${INITDB_FLAGS} >& ${DB_DIR}/initdb_log.txt
3031

32+
POSTGRES_FLAGS=""
3133
POSTGRES_FLAGS+=" -p 9100"
3234
POSTGRES_FLAGS+=" -D ${DB_DIR}/db"
3335
POSTGRES_FLAGS+=" -k ${DB_DIR}/db"
@@ -49,4 +51,3 @@ kill -15 ${PG_PID}
4951
wait ${PG_PID}
5052
[ ${RC} -ne 0 ] && (rm -rf ${DB_DIR})
5153
exit ${RC}
52-

tests/lit.cfg

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os
44
import platform
5-
import glob
5+
import shutil
66

77
import lit.formats
88
import lit.util
@@ -46,9 +46,11 @@ config.substitutions.append(('%{test_exec_root}', config.test_exec_root))
4646
if lit_config.params.get('long', None):
4747
config.available_features.add('long')
4848

49-
# Enable postgres testing. This requires postgres binaries in PATH.
50-
# (You do not need to start a server, the tests will create ad-hoc instances).
51-
if lit_config.params.get('postgres', None):
49+
# Enable postgres database support testing if the postgres binary can be found.
50+
# Note that you do not need to setup an actual server, the tests will create
51+
# temporary instances on demand.
52+
postgres = shutil.which('postgres')
53+
if postgres is not None:
5254
config.available_features.add('postgres')
5355

5456
# Enable MySQL testing. This requires mysqld and mysqladmin binaries in PATH.

tests/lnttool/PostgresDB.shtest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# REQUIRES: postgres
22
# RUN: rm -rf "%t.install"
3-
# RUN: %{shared_inputs}/postgres_wrapper.sh "%t.install" /bin/sh %s "%t.install" postgresql://pgtest@localhost:9100 "%{shared_inputs}"
3+
# RUN: %{shared_inputs}/postgres_wrapper.sh "%t.install" bash %s "%t.install" postgresql://pgtest@localhost:9100 "%{shared_inputs}"
44
set -eux
55

66
TESTDIR="$1"

0 commit comments

Comments
 (0)