pgrx icon indicating copy to clipboard operation
pgrx copied to clipboard

how to test GucContext::SuBackend

Open mrl5 opened this issue 4 months ago • 7 comments

hello, let's assume that I have this GUC initialization logic:

use pgrx::*;
use std::ffi::CStr;

pub static MY_FOO_RUNTIME_PARAM: &str = "my.foo";
pub static MY_FOO: GucSetting<Option<&'static CStr>> = GucSetting::<Option<&'static CStr>>::new(None);

pub fn init() {
    GucRegistry::define_string_guc(
        MY_FOO_RUNTIME_PARAM,
        "My Foo",
        "That can be FooBar",
        &MY_FOO,
        GucContext::SuBackend,
        GucFlags::NOT_WHILE_SEC_REST
    );
}
  1. How can I properly set it for unit tests? I've tried with some util function that works for GucContext::Suset:
fn set_my_foo_in_guc(value: String) {
    Spi::run(format!("SET {} = '{}'", MY_FOO_RUNTIME_PARAM, value).as_str()).unwrap();
}

but - as expected - I'm getting

Client Error:
parameter "my.foo" cannot be set after connection start
postgres location: guc.c
  1. For manual tests, how can set this GUC param in cargo pgrx run pg16?

mrl5 avatar Oct 09 '24 08:10 mrl5