Skip to content

how to test GucContext::SuBackend #1906

@mrl5

Description

@mrl5

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions