diff --git a/.github/workflows/tox.yaml b/.github/workflows/tox.yaml index d0a4c542..ae38c812 100644 --- a/.github/workflows/tox.yaml +++ b/.github/workflows/tox.yaml @@ -7,10 +7,12 @@ on: jobs: build: runs-on: ubuntu-latest + name: "Python ${{ matrix.python-version }}, Postgres=${{ matrix.with-postgres }}" strategy: matrix: python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] + with-postgres: [true, false] fail-fast: false steps: @@ -25,6 +27,11 @@ jobs: run: | python -m pip install --upgrade pip pip install tox tox-gh-actions + - name: Install PostgreSQL + if: ${{ matrix.with-postgres }} + uses: tj-actions/install-postgresql@v3 + with: + postgresql-version: 17 - name: Tox flake8 run: tox -e flake8 - name: Tox docs diff --git a/docs/developer_guide.rst b/docs/developer_guide.rst index 1b13a8d8..06879d99 100644 --- a/docs/developer_guide.rst +++ b/docs/developer_guide.rst @@ -51,12 +51,6 @@ Optional Tests Some tests require additional tools to be installed and are not enabled by default. You can enable them by passing additional flags to ``lit``: - ``-Dpostgres=1`` - Enable postgres database support testing. This requires at least - postgres version 9.2 and the ``initdb`` and ``postgres`` binaries in your path. - Note that you do not need to setup an actual server, the tests will create - temporary instances on demand. - ``-Dmysql=1`` Enable mysql database support testing. This requires MySQL-python to be 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``: Example:: - lit -sv -Dpostgres=1 -Dmysql=1 -Dtidylib=1 ./tests + lit -sv -Dmysql=1 -Dtidylib=1 ./tests Publishing a new version of LNT ------------------------------- diff --git a/pyproject.toml b/pyproject.toml index e4da9cb3..a5c59abc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,7 +66,9 @@ dev = [ "filecheck", "Flake8-pyproject", "flake8", + "gunicorn>=19.9.0", "lit", + "psycopg2>=2.9.0", "tox", "twine", ] @@ -120,7 +122,7 @@ allowlist_externals = ["rm", "lit"] deps = [".[dev]"] commands = [ ["rm", "-rf", "test_run_tmp"], - ["lit", "-sv", "tests"], + ["lit", "-sv", "--show-unsupported", "tests"], ] [tool.tox.env.flake8] diff --git a/tests/SharedInputs/postgres_wrapper.sh b/tests/SharedInputs/postgres_wrapper.sh index 76ceec21..4c26299c 100755 --- a/tests/SharedInputs/postgres_wrapper.sh +++ b/tests/SharedInputs/postgres_wrapper.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash # Setup minimalistic postgres instance in specified directory, start a server, # run the given command and shutdown the server. Use # `postgresql://pgtest@localhost:9100` to connect to the server. @@ -10,7 +10,7 @@ set -u TEST_DIR=$1 shift -DB_DIR="$(mktemp -d -t lnt)" +DB_DIR="$(mktemp -d -t lnt.XXXXX)" if [ -d "${TEST_DIR}" ]; then echo 1>&2 "${TEST_DIR} already exists" exit 1 @@ -19,8 +19,9 @@ fi mkdir -p "${TEST_DIR}" ln -s ${TEST_DIR}/db_root ${DB_DIR} +INITDB_FLAGS="" INITDB_FLAGS+=" --pgdata=${DB_DIR}/db" -INITDB_FLAGS+=" --xlogdir=${DB_DIR}/db" +INITDB_FLAGS+=" --waldir=${DB_DIR}/db" INITDB_FLAGS+=" --nosync" INITDB_FLAGS+=" --no-locale" INITDB_FLAGS+=" --auth=trust" @@ -28,6 +29,7 @@ INITDB_FLAGS+=" --username=pgtest" echo "$ initdb $INITDB_FLAGS >& ${DB_DIR}/initdb_log.txt" initdb ${INITDB_FLAGS} >& ${DB_DIR}/initdb_log.txt +POSTGRES_FLAGS="" POSTGRES_FLAGS+=" -p 9100" POSTGRES_FLAGS+=" -D ${DB_DIR}/db" POSTGRES_FLAGS+=" -k ${DB_DIR}/db" @@ -49,4 +51,3 @@ kill -15 ${PG_PID} wait ${PG_PID} [ ${RC} -ne 0 ] && (rm -rf ${DB_DIR}) exit ${RC} - diff --git a/tests/lit.cfg b/tests/lit.cfg index d48fafc7..cb78e865 100644 --- a/tests/lit.cfg +++ b/tests/lit.cfg @@ -2,7 +2,7 @@ import os import platform -import glob +import shutil import lit.formats import lit.util @@ -46,9 +46,11 @@ config.substitutions.append(('%{test_exec_root}', config.test_exec_root)) if lit_config.params.get('long', None): config.available_features.add('long') -# Enable postgres testing. This requires postgres binaries in PATH. -# (You do not need to start a server, the tests will create ad-hoc instances). -if lit_config.params.get('postgres', None): +# Enable postgres database support testing if the postgres binary can be found. +# Note that you do not need to setup an actual server, the tests will create +# temporary instances on demand. +postgres = shutil.which('postgres') +if postgres is not None: config.available_features.add('postgres') # Enable MySQL testing. This requires mysqld and mysqladmin binaries in PATH. diff --git a/tests/lnttool/PostgresDB.shtest b/tests/lnttool/PostgresDB.shtest index ef506c25..eb780129 100644 --- a/tests/lnttool/PostgresDB.shtest +++ b/tests/lnttool/PostgresDB.shtest @@ -1,6 +1,6 @@ # REQUIRES: postgres # RUN: rm -rf "%t.install" -# RUN: %{shared_inputs}/postgres_wrapper.sh "%t.install" /bin/sh %s "%t.install" postgresql://pgtest@localhost:9100 "%{shared_inputs}" +# RUN: %{shared_inputs}/postgres_wrapper.sh "%t.install" bash %s "%t.install" postgresql://pgtest@localhost:9100 "%{shared_inputs}" set -eux TESTDIR="$1"