Skip to content

Commit

Permalink
Add a test matrix on CI for postgres versions (#135)
Browse files Browse the repository at this point in the history
* Add a test matrix on CI for postgres versions

* Fixes/improvements

* Remove pg16 feature

Requires bumping pgrx

* Add pg12 and pg13 in test matrix

* make test should accept pgrx pg version

* Set feature when running tests
  • Loading branch information
v0idpwn authored Oct 6, 2023
1 parent bb7b646 commit fea375d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
11 changes: 8 additions & 3 deletions .github/actions/pgx-init/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
29 changes: 22 additions & 7 deletions .github/workflows/extension_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ jobs:
test:
name: Run tests
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
pg: [
{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"},
]
steps:
- uses: actions/checkout@v2
- name: Install Rust stable toolchain
Expand All @@ -59,7 +70,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
Expand All @@ -68,19 +79,23 @@ 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 postgresql-server-dev-14
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 && \
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
make test
cargo pgrx run ${{ matrix.pg.pgrx_version }} --pgcli || true
PGRX_POSTGRES=${{ matrix.pg.pgrx_version }} make test
publish:
# only publish release events
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
PGRX_POSTGRES ?= pg15

test:
cargo pgrx test
cargo test -- --test-threads=1 --ignored
cargo pgrx test $(PGRX_POSTGRES)
cargo test --no-default-features --features ${PGRX_POSTGRES} -- --test-threads=1 --ignored

format:
cargo +nightly fmt --all
Expand Down
22 changes: 19 additions & 3 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ async fn connect(url: &str) -> Pool<Postgres> {

async fn init_database() -> Pool<Postgres> {
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!
Expand Down Expand Up @@ -669,7 +670,22 @@ async fn send_sample_message(queue_name: &String, conn: &Pool<Postgres>) -> i64
.get::<i64, usize>(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
}
}

0 comments on commit fea375d

Please sign in to comment.