From: Daniele Varrazzo Date: Tue, 14 Jun 2022 14:57:01 +0000 (+0200) Subject: test: verify that we distribute the libpq we want to build X-Git-Tag: 3.1~57^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3b7097d570baa6999b569ccaba4b07f746f43099;p=thirdparty%2Fpsycopg.git test: verify that we distribute the libpq we want to build --- diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml index f1c9f4b3b..2297f1357 100644 --- a/.github/workflows/packages.yml +++ b/.github/workflows/packages.yml @@ -80,6 +80,10 @@ jobs: linux: # {{{ runs-on: ubuntu-20.04 + env: + LIBPQ_VERSION: "14.3" + OPENSSL_VERSION: "1.1.1o" + strategy: fail-fast: false matrix: @@ -97,7 +101,7 @@ jobs: uses: actions/cache@v3 with: path: /tmp/libpq.build - key: libpq-14.3-${{ matrix.platform }}-${{ matrix.arch }}-1 + key: libpq-${{ env.LIBPQ_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-1 - name: Create the binary package source tree run: python3 ./tools/build/copy_to_binary.py @@ -120,6 +124,7 @@ jobs: CIBW_TEST_REQUIRES: ./psycopg[test] ./psycopg_pool CIBW_TEST_COMMAND: >- pytest {project}/tests -m 'not slow and not flakey' --color yes + CIBW_ENVIRONMENT_PASS_LINUX: LIBPQ_VERSION OPENSSL_VERSION CIBW_ENVIRONMENT: >- PSYCOPG_IMPL=binary PSYCOPG_TEST_DSN='host=172.17.0.1 user=postgres' @@ -127,6 +132,8 @@ jobs: LIBPQ_BUILD_PREFIX=/host/tmp/libpq.build PATH="$LIBPQ_BUILD_PREFIX/bin:$PATH" LD_LIBRARY_PATH="$LIBPQ_BUILD_PREFIX/lib" + PSYCOPG_TEST_WANT_LIBPQ_BUILD=${{ env.LIBPQ_VERSION }} + PSYCOPG_TEST_WANT_LIBPQ_IMPORT=${{ env.LIBPQ_VERSION }} - uses: actions/upload-artifact@v2 with: @@ -182,6 +189,8 @@ jobs: CIBW_ENVIRONMENT: >- PSYCOPG_IMPL=binary PSYCOPG_TEST_DSN='dbname=postgres' + PSYCOPG_TEST_WANT_LIBPQ_BUILD=">= 14" + PSYCOPG_TEST_WANT_LIBPQ_IMPORT=">= 14" - uses: actions/upload-artifact@v2 with: @@ -230,6 +239,8 @@ jobs: PSYCOPG_IMPL=binary PATH="C:\\Program Files\\PostgreSQL\\14\\bin;$PATH" PSYCOPG_TEST_DSN="host=127.0.0.1 user=postgres" + PSYCOPG_TEST_WANT_LIBPQ_BUILD=">= 14" + PSYCOPG_TEST_WANT_LIBPQ_IMPORT=">= 14" - uses: actions/upload-artifact@v2 with: diff --git a/psycopg/tox.ini b/psycopg/tox.ini index 494b53ab3..a1dc963dd 100644 --- a/psycopg/tox.ini +++ b/psycopg/tox.ini @@ -19,7 +19,7 @@ commands = -python -bb -m pytest {posargs} -python -bb -m pytest --lf --lfnf=none --no-collect-ok --randomly-seed=last {posargs} python -bb -m pytest --lf --lfnf=none --no-collect-ok --randomly-seed=last {posargs} -passenv = PG* PSYCOPG_TEST_DSN PYTEST_ADDOPTS PSYCOPG_IMPL PIP_CONSTRAINT +passenv = PG* PSYCOPG_TEST_* PYTEST_ADDOPTS PSYCOPG_IMPL PIP_CONSTRAINT extras = test deps = -e {toxinidir}/../psycopg_pool diff --git a/psycopg_c/tox.ini b/psycopg_c/tox.ini index a77cf45e1..ca4cfc3ac 100644 --- a/psycopg_c/tox.ini +++ b/psycopg_c/tox.ini @@ -8,7 +8,7 @@ commands = -python -bb -m pytest {posargs} -python -bb -m pytest --lf --lfnf=none --no-collect-ok --randomly-seed=last {posargs} python -bb -m pytest --lf --lfnf=none --no-collect-ok --randomly-seed=last {posargs} -passenv = PG* PSYCOPG_TEST_DSN PYTEST_ADDOPTS PSYCOPG_IMPL PIP_CONSTRAINT +passenv = PG* PSYCOPG_TEST_* PYTEST_ADDOPTS PSYCOPG_IMPL PIP_CONSTRAINT deps = -e {toxinidir}/../psycopg[test] -e {toxinidir}/../psycopg_pool diff --git a/tests/pq/test_pq.py b/tests/pq/test_pq.py index 41e4b72a1..d344d1213 100644 --- a/tests/pq/test_pq.py +++ b/tests/pq/test_pq.py @@ -1,6 +1,12 @@ +import os + +import pytest + import psycopg from psycopg import pq +from ..utils import check_libpq_version + def test_version(): rv = pq.version() @@ -17,6 +23,20 @@ def test_build_version(): assert False, f"unexpected libpq implementation: {pq.__impl__}" +@pytest.mark.skipif("not os.environ.get('PSYCOPG_TEST_WANT_LIBPQ_BUILD')") +def test_want_built_version(): + want = os.environ["PSYCOPG_TEST_WANT_LIBPQ_BUILD"] + got = pq.__build_version__ + assert not check_libpq_version(got, want) + + +@pytest.mark.skipif("not os.environ.get('PSYCOPG_TEST_WANT_LIBPQ_IMPORT')") +def test_want_import_version(): + want = os.environ["PSYCOPG_TEST_WANT_LIBPQ_IMPORT"] + got = pq.version() + assert not check_libpq_version(got, want) + + def test_pipeline_supported(): # Note: This test is here because pipeline tests are skipped on libpq < 14 if pq.__impl__ == "python": diff --git a/tests/utils.py b/tests/utils.py index 80ec6afd8..ec1cba446 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -34,6 +34,11 @@ def check_server_version(got, want): def _check_version(got, want, whose_version): + """Check that a postgres-style version matches a desired spec. + + - The postgres-style version is a number such as 90603 for 9.6.3. + - The want version is a spec string such as "> 9.6" + """ # convert 90603 to (9, 6, 3), 120003 to (12, 3) got, got_fix = divmod(got, 100) got_maj, got_min = divmod(got, 100) @@ -43,7 +48,10 @@ def _check_version(got, want, whose_version): got = (got_maj, got_min, got_fix) # Parse a spec like "> 9.6" - m = re.match(r"^\s*(>=|<=|>|<)\s*(?:(\d+)(?:\.(\d+)(?:\.(\d+))?)?)?\s*$", want) + m = re.match( + r"^\s*(>=|<=|>|<|==)?\s*(?:(\d+)(?:\.(\d+)(?:\.(\d+))?)?)?\s*$", + want, + ) if m is None: pytest.fail(f"bad wanted version spec: {want}") @@ -58,12 +66,13 @@ def _check_version(got, want, whose_version): else: want = (want_maj, want_min, want_fix) - op = getattr(operator, {">=": "ge", "<=": "le", ">": "gt", "<": "lt"}[m.group(1)]) + opnames = {">=": "ge", "<=": "le", ">": "gt", "<": "lt", "==": "eq"} + op = getattr(operator, opnames[m.group(1) or "=="]) if not op(got, want): - revops = {">=": "<", "<=": ">", ">": "<=", "<": ">="} + revops = {">=": "<", "<=": ">", ">": "<=", "<": ">=", "==": "!="} return ( - f"skipping test: {whose_version} version is {'.'.join(map(str, got))}" + f"{whose_version} version is {'.'.join(map(str, got))}" f" {revops[m.group(1)]} {'.'.join(map(str, want))}" ) diff --git a/tools/build/build_libpq.sh b/tools/build/build_libpq.sh index e098ba7c0..35a346a6a 100755 --- a/tools/build/build_libpq.sh +++ b/tools/build/build_libpq.sh @@ -5,10 +5,17 @@ set -euo pipefail set -x +# Last release: https://www.postgresql.org/ftp/source/ # IMPORTANT! Change the cache key in packages.yml when upgrading libraries -postgres_version="14.3" -openssl_version="1.1.1o" +postgres_version="${LIBPQ_VERSION:-14.3}" + +# last release: https://www.openssl.org/source/ +openssl_version="${OPENSSL_VERSION:-1.1.1o}" + +# last release: https://openldap.org/software/download/ ldap_version="2.6.2" + +# last release: https://github.com/cyrusimap/cyrus-sasl/releases sasl_version="2.1.28" export LIBPQ_BUILD_PREFIX=${LIBPQ_BUILD_PREFIX:-/tmp/libpq.build}