From 61d248247939333b7239210a932661571e18febb Mon Sep 17 00:00:00 2001 From: v0idpwn Date: Thu, 5 Oct 2023 20:53:55 +0300 Subject: [PATCH 01/11] Add a test matrix on CI for postgres versions --- .github/workflows/extension_ci.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/extension_ci.yml b/.github/workflows/extension_ci.yml index 85d32be2..e959c95b 100644 --- a/.github/workflows/extension_ci.yml +++ b/.github/workflows/extension_ci.yml @@ -51,6 +51,13 @@ jobs: test: name: Run tests runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + pg: [ + {version: "14.9", pgrx_version: "pg14", server_dev: "postgresql-server-dev-14"}, + {version: "15.4", pgrx_version: "pg15", server_dev: "postgresql-server-dev-15"}, + ] steps: - uses: actions/checkout@v2 - name: Install Rust stable toolchain @@ -70,16 +77,15 @@ jobs: working-directory: ./ - name: test run: | - sudo apt-get update && sudo apt-get install -y postgresql-server-dev-14 + sudo apt-get update && sudo apt-get install -y ${{ matrix.pg.server_dev }} git clone https://github.com/pgpartman/pg_partman.git && \ cd pg_partman && \ git checkout v4.7.4 && \ sudo make install && cd ../ - cp /usr/share/postgresql/14/extension/pg_partman* ~/.pgrx/15.4/pgrx-install/share/postgresql/extension/ - cp /usr/lib/postgresql/14/lib/pg_partman_bgw.so ~/.pgrx/15.4/pgrx-install/lib/postgresql/ + cp /usr/share/postgresql/14/extension/pg_partman* ~/.pgrx/${{ matrix.pg.version }}/pgrx-install/share/postgresql/extension/ + cp /usr/lib/postgresql/14/lib/pg_partman_bgw.so ~/.pgrx/${{ matrix.pg.version }}/pgrx-install/lib/postgresql/ rm -rf ./target/pgrx-test-data-* || true - pg_version=$(stoml Cargo.toml features.default) - cargo pgrx run ${pg_version} --pgcli || true + cargo pgrx run ${{ matrix.pg.pgrx_version }} --pgcli || true make test publish: From 61f5a5150626ccb69e1095493cf086050fd73b0e Mon Sep 17 00:00:00 2001 From: v0idpwn Date: Thu, 5 Oct 2023 21:20:30 +0300 Subject: [PATCH 02/11] Fixes/improvements --- .github/actions/pgx-init/action.yml | 11 ++++++++--- .github/workflows/extension_ci.yml | 9 ++++++--- Cargo.toml | 1 + 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/actions/pgx-init/action.yml b/.github/actions/pgx-init/action.yml index a5644af6..431606e5 100644 --- a/.github/actions/pgx-init/action.yml +++ b/.github/actions/pgx-init/action.yml @@ -4,6 +4,12 @@ inputs: working-directory: description: 'The directory in which there is a pgrx extension project' required: true + pg_version: + description: 'The version of postgres' + default: "15.4" + pgrx_pg_version: + description: 'Pgrx pg version alias' + default: "pg15" outputs: {} runs: using: "composite" @@ -35,12 +41,11 @@ runs: working-directory: ${{ inputs.working-directory }} run: | set -x - pg_version=$(stoml Cargo.toml features.default) # pgrx init can take a long time, and it re-compiles postgres even when there # is a cached version. So, we can just check for the directory and cat /home/runner/.pgrx/config.toml || true - if find /home/runner/.pgrx | grep $(awk -F "=" '/${pg_version}/ {print $2}' /home/runner/.pgrx/config.toml | tr -d '"'); then + if find /home/runner/.pgrx | grep $(awk -F "=" '/${{ inputs.pg_version}}/ {print $2}' /home/runner/.pgrx/config.toml | tr -d '"'); then echo "Already found pgrx is initialized. Skipping 'cargo pgrx init' command." else - cargo pgrx init --${pg_version} download || true + cargo pgrx init --${{inputs.pgrx_pg_version}} download || true fi diff --git a/.github/workflows/extension_ci.yml b/.github/workflows/extension_ci.yml index e959c95b..5d45feac 100644 --- a/.github/workflows/extension_ci.yml +++ b/.github/workflows/extension_ci.yml @@ -55,8 +55,9 @@ jobs: fail-fast: false matrix: pg: [ - {version: "14.9", pgrx_version: "pg14", server_dev: "postgresql-server-dev-14"}, - {version: "15.4", pgrx_version: "pg15", server_dev: "postgresql-server-dev-15"}, + {version: "14.9", pgrx_version: "pg14", server_dev: "postgresql-server-dev-all"}, + {version: "15.4", pgrx_version: "pg15", server_dev: "postgresql-server-dev-all"}, + {version: "16.0", pgrx_version: "pg16", server_dev: "postgresql-server-dev-all"}, ] steps: - uses: actions/checkout@v2 @@ -66,7 +67,7 @@ jobs: toolchain: stable - uses: Swatinem/rust-cache@v2 with: - prefix-key: "pgmq-extension-test" + prefix-key: "pgmq-extension-test-${{ matrix.pg.pgrx_version }}" workspaces: | pgmq # Additional directories to cache @@ -75,6 +76,8 @@ jobs: - uses: ./.github/actions/pgx-init with: working-directory: ./ + pgrx_pg_version: ${{ matrix.pg.pgrx_version }} + pg_version: ${{ matrix.pg.version }} - name: test run: | sudo apt-get update && sudo apt-get install -y ${{ matrix.pg.server_dev }} diff --git a/Cargo.toml b/Cargo.toml index e5741a4c..0bdf9bcd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ pg12 = ["pgrx/pg12", "pgrx-tests/pg12"] pg13 = ["pgrx/pg13", "pgrx-tests/pg13"] pg14 = ["pgrx/pg14", "pgrx-tests/pg14"] pg15 = ["pgrx/pg15", "pgrx-tests/pg15"] +pg16 = ["pgrx/pg16", "pgrx-tests/pg16"] pg_test = [] [dependencies] From c81468cb9ec3b88ca8362e835dd889ca3f33883d Mon Sep 17 00:00:00 2001 From: v0idpwn Date: Thu, 5 Oct 2023 21:24:58 +0300 Subject: [PATCH 03/11] Remove pg16 feature Requires bumping pgrx --- .github/workflows/extension_ci.yml | 2 +- Cargo.toml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/extension_ci.yml b/.github/workflows/extension_ci.yml index 5d45feac..9f5b9518 100644 --- a/.github/workflows/extension_ci.yml +++ b/.github/workflows/extension_ci.yml @@ -57,7 +57,7 @@ jobs: pg: [ {version: "14.9", pgrx_version: "pg14", server_dev: "postgresql-server-dev-all"}, {version: "15.4", pgrx_version: "pg15", server_dev: "postgresql-server-dev-all"}, - {version: "16.0", pgrx_version: "pg16", server_dev: "postgresql-server-dev-all"}, + #{version: "16.0", pgrx_version: "pg16", server_dev: "postgresql-server-dev-all"}, ] steps: - uses: actions/checkout@v2 diff --git a/Cargo.toml b/Cargo.toml index 0bdf9bcd..e5741a4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,6 @@ pg12 = ["pgrx/pg12", "pgrx-tests/pg12"] pg13 = ["pgrx/pg13", "pgrx-tests/pg13"] pg14 = ["pgrx/pg14", "pgrx-tests/pg14"] pg15 = ["pgrx/pg15", "pgrx-tests/pg15"] -pg16 = ["pgrx/pg16", "pgrx-tests/pg16"] pg_test = [] [dependencies] From ecb168f9e9684b81cbf17549e2dbfa2094c34a52 Mon Sep 17 00:00:00 2001 From: v0idpwn Date: Thu, 5 Oct 2023 21:32:54 +0300 Subject: [PATCH 04/11] Add pg12 and pg13 in test matrix --- .github/workflows/extension_ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/extension_ci.yml b/.github/workflows/extension_ci.yml index 9f5b9518..bef09ceb 100644 --- a/.github/workflows/extension_ci.yml +++ b/.github/workflows/extension_ci.yml @@ -55,9 +55,12 @@ jobs: fail-fast: false matrix: pg: [ + {version: "12.16", pgrx_version: "pg12", server_dev: "postgresql-server-dev-all"}, + {version: "13.12", pgrx_version: "pg13", server_dev: "postgresql-server-dev-all"}, {version: "14.9", pgrx_version: "pg14", server_dev: "postgresql-server-dev-all"}, {version: "15.4", pgrx_version: "pg15", server_dev: "postgresql-server-dev-all"}, - #{version: "16.0", pgrx_version: "pg16", server_dev: "postgresql-server-dev-all"}, + #TODO: must update pgrx to support pg16 + # {version: "16.0", pgrx_version: "pg16", server_dev: "postgresql-server-dev-all"}, ] steps: - uses: actions/checkout@v2 From f9e8a554c38418843852f0916d6c2589ed86d3b7 Mon Sep 17 00:00:00 2001 From: v0idpwn Date: Thu, 5 Oct 2023 21:48:47 +0300 Subject: [PATCH 05/11] Attempt --- .github/workflows/extension_ci.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/extension_ci.yml b/.github/workflows/extension_ci.yml index bef09ceb..47d27bbd 100644 --- a/.github/workflows/extension_ci.yml +++ b/.github/workflows/extension_ci.yml @@ -55,10 +55,10 @@ jobs: fail-fast: false matrix: pg: [ - {version: "12.16", pgrx_version: "pg12", server_dev: "postgresql-server-dev-all"}, - {version: "13.12", pgrx_version: "pg13", server_dev: "postgresql-server-dev-all"}, - {version: "14.9", pgrx_version: "pg14", server_dev: "postgresql-server-dev-all"}, - {version: "15.4", pgrx_version: "pg15", server_dev: "postgresql-server-dev-all"}, + {version: "12.16", pgrx_version: "pg12"}, + {version: "13.12", pgrx_version: "pg13"}, + {version: "14.9", pgrx_version: "pg14"}, + {version: "15.4", pgrx_version: "pg15"}, #TODO: must update pgrx to support pg16 # {version: "16.0", pgrx_version: "pg16", server_dev: "postgresql-server-dev-all"}, ] @@ -83,7 +83,9 @@ jobs: pg_version: ${{ matrix.pg.version }} - name: test run: | - sudo apt-get update && sudo apt-get install -y ${{ matrix.pg.server_dev }} + sudo apt-get update + sudo apt-get install -y postgresql-common=238 postgresql-server-dev-14 + sudo apt-get install -y postgresql-server-dev-all git clone https://github.com/pgpartman/pg_partman.git && \ cd pg_partman && \ git checkout v4.7.4 && \ From 36331dca33b27589110cf11a52fae49d9e19ffce Mon Sep 17 00:00:00 2001 From: v0idpwn Date: Thu, 5 Oct 2023 22:27:43 +0300 Subject: [PATCH 06/11] attempt 2 --- .github/workflows/extension_ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/extension_ci.yml b/.github/workflows/extension_ci.yml index 47d27bbd..f56c5120 100644 --- a/.github/workflows/extension_ci.yml +++ b/.github/workflows/extension_ci.yml @@ -84,8 +84,8 @@ jobs: - name: test run: | sudo apt-get update - sudo apt-get install -y postgresql-common=238 postgresql-server-dev-14 - sudo apt-get install -y postgresql-server-dev-all + sudo apt-get install -y --allow-downgrades postgresql-common=238 postgresql-server-dev-14 + sudo apt-get install -y --allow-downgrades postgresql-server-dev-all git clone https://github.com/pgpartman/pg_partman.git && \ cd pg_partman && \ git checkout v4.7.4 && \ From adf27ded6650bb5fc1ac343eb9c0dba252cb24da Mon Sep 17 00:00:00 2001 From: v0idpwn Date: Thu, 5 Oct 2023 23:07:43 +0300 Subject: [PATCH 07/11] attempt 3 --- .github/workflows/extension_ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/extension_ci.yml b/.github/workflows/extension_ci.yml index f56c5120..ef9388d8 100644 --- a/.github/workflows/extension_ci.yml +++ b/.github/workflows/extension_ci.yml @@ -84,6 +84,7 @@ jobs: - name: test run: | sudo apt-get update + sudo apt-get install -y --allow-downgrades postgresql-client-common=238 sudo apt-get install -y --allow-downgrades postgresql-common=238 postgresql-server-dev-14 sudo apt-get install -y --allow-downgrades postgresql-server-dev-all git clone https://github.com/pgpartman/pg_partman.git && \ From 78d14e61569cc1888a42bded746852db6f85859a Mon Sep 17 00:00:00 2001 From: v0idpwn Date: Thu, 5 Oct 2023 23:34:33 +0300 Subject: [PATCH 08/11] make test should accept pgrx pg version --- .github/workflows/extension_ci.yml | 2 +- Makefile | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/extension_ci.yml b/.github/workflows/extension_ci.yml index ef9388d8..35b29d70 100644 --- a/.github/workflows/extension_ci.yml +++ b/.github/workflows/extension_ci.yml @@ -95,7 +95,7 @@ jobs: cp /usr/lib/postgresql/14/lib/pg_partman_bgw.so ~/.pgrx/${{ matrix.pg.version }}/pgrx-install/lib/postgresql/ rm -rf ./target/pgrx-test-data-* || true cargo pgrx run ${{ matrix.pg.pgrx_version }} --pgcli || true - make test + PGRX_POSTGRES=${{ matrix.pg.pgrx_version }} make test publish: # only publish release events diff --git a/Makefile b/Makefile index 4dad260c..64d11bce 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ +PGRX_POSTGRES ?= pg15 + test: - cargo pgrx test + cargo pgrx test $(PGRX_POSTGRES) cargo test -- --test-threads=1 --ignored format: From dd5f3f5410db89aaa45767cdc88b6cd43b9af1a1 Mon Sep 17 00:00:00 2001 From: v0idpwn Date: Fri, 6 Oct 2023 00:25:44 +0300 Subject: [PATCH 09/11] Set feature when running tests --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 64d11bce..7d3e087e 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ PGRX_POSTGRES ?= pg15 test: cargo pgrx test $(PGRX_POSTGRES) - cargo test -- --test-threads=1 --ignored + cargo test --no-default-features --features ${PGRX_POSTGRES} -- --test-threads=1 --ignored format: cargo +nightly fmt --all From 3daebf7b40186f0c5012114b79cbc3f34f40047b Mon Sep 17 00:00:00 2001 From: v0idpwn Date: Fri, 6 Oct 2023 11:20:55 +0300 Subject: [PATCH 10/11] Consider pg version feature when deciding which port to test on --- tests/integration_tests.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 683f813f..406d5c7c 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -40,9 +40,10 @@ async fn connect(url: &str) -> Pool { async fn init_database() -> Pool { let username = whoami::username(); + let database_port = database_port(); let conn00 = connect(&format!( - "postgres://{username}:postgres@localhost:28815/pgmq" + "postgres://{username}:postgres@localhost:{database_port}/pgmq" )) .await; // ignore the error if the db already exists! @@ -669,7 +670,22 @@ async fn send_sample_message(queue_name: &String, conn: &Pool) -> i64 .get::(0) } -pub fn database_name() -> String { +fn database_name() -> String { let username = whoami::username(); - format!("postgres://{username}:postgres@localhost:28815/pgmq_test") + let database_port = database_port(); + format!("postgres://{username}:postgres@localhost:{database_port}/pgmq_test") +} + +fn database_port() -> usize { + if cfg!(feature = "pg15") { + 28815 + } else if cfg!(feature = "pg14") { + 28814 + } else if cfg!(feature = "pg13") { + 28813 + } else if cfg!(feature = "pg12") { + 28812 + } else { + 5432 + } } From 44a2ee111183773e641f18153d91ac8f67eb490f Mon Sep 17 00:00:00 2001 From: v0idpwn Date: Fri, 6 Oct 2023 13:59:58 +0300 Subject: [PATCH 11/11] trigger ci