fix(pgrx-tests): respect configured PostgreSQL GUCs#2337
Conversation
0xPoe
left a comment
There was a problem hiding this comment.
🔢 Self-check (PR reviewed by myself and ready for feedback)
-
Code compiles successfully
-
Unit tests added
-
No AI-generated elegant nonsense in PR.
-
Comments added where necessary
-
PR title and description updated
-
PR size is reasonable
|
Rather than issuing SETs ourselves I think we should bake pgrx's defaults into "postgresql.conf" and allow what an extension specifies in its Thoughts? Wanna rework this? |
Makes sense. I'll rework this by moving the pgrx logging defaults into the generated Postgres config. |
|
I have tested locally:
WORK="$(mktemp -d)"
cd "$WORK"
cargo install --git "https://github.com/0xPoe/pgrx.git" --branch "poe-patch-guc" cargo-pgrx --root "$WORK/.tools"
"$WORK/.tools/bin/cargo-pgrx" pgrx new pgrx_issue2151_check
cd pgrx_issue2151_check
[patch.crates-io]
pgrx = { git = "https://github.com/0xPoe/pgrx.git", branch = "poe-patch-guc" }
pgrx-tests = { git = "https://github.com/0xPoe/pgrx.git", branch = "poe-patch-guc" }
cat > src/lib.rs <<'EOF'
use pgrx::prelude::*;
::pgrx::pg_module_magic!(name, version);
#[pg_extern]
fn hello_pgrx_issue2151_check() -> &'static str {
"Hello, pgrx_issue2151_check"
}
#[cfg(any(test, feature = "pg_test"))]
#[pg_schema]
mod tests {
#[pgrx::pg_test]
fn postgresql_conf_options_controls_log_min_messages() {
let value = pgrx::Spi::get_one::<String>("SELECT current_setting('log_min_messages');")
.expect("SPI should succeed")
.expect("current_setting should return a value");
assert_eq!(value, "debug1");
}
}
/// This module is required by `cargo pgrx test` invocations.
/// It must be visible at the root of your extension crate.
#[cfg(test)]
pub mod pg_test {
pub fn setup(_options: Vec<&str>) {}
#[must_use]
pub fn postgresql_conf_options() -> Vec<&'static str> {
vec!["log_min_messages = debug1"]
}
}
EOF
CARGO_PGRX_TEST_PGDATA="$WORK/pgdata" \
cargo test --no-default-features --features pg18 --lib \
postgresql_conf_options_controls_log_min_messages -- --nocapture
test tests::pg_postgresql_conf_options_controls_log_min_messages ... ok |
0xPoe
left a comment
There was a problem hiding this comment.
🔢 Self-check (PR reviewed by myself and ready for feedback)
close #2151
pgrx-tests sets a few session-level logging defaults when creating a client. In this PR, I have baked pgrx's defaults into
postgresql.conf. Now they can be overridden by the user'spostgresql_conf_options.I just added a simple unit test instead of an integration test, as there is no existing integration test suite in the
pgrx-testscrate.