Skip to content

Commit

Permalink
fail if test framework initialization failed
Browse files Browse the repository at this point in the history
  • Loading branch information
usamoi committed Nov 2, 2024
1 parent 5fd1d9f commit 4b32992
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions pgrx-tests/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub fn run_test(
);
return Ok(());
}
let (loglines, system_session_id) = initialize_test_framework(postgresql_conf)?;
let (loglines, system_session_id) = get_test_framework(postgresql_conf)?;

let (mut client, session_id) = client()?;

Expand Down Expand Up @@ -190,9 +190,7 @@ fn format_loglines(session_id: &str, loglines: &LogLines) -> String {
result
}

fn initialize_test_framework(
postgresql_conf: Vec<&'static str>,
) -> eyre::Result<(LogLines, String)> {
fn get_test_framework(postgresql_conf: Vec<&'static str>) -> eyre::Result<(LogLines, String)> {
let mut state = TEST_MUTEX
.get_or_init(|| {
Mutex::new(SetupState {
Expand All @@ -212,22 +210,31 @@ fn initialize_test_framework(
});

if !state.installed {
shutdown::register_shutdown_hook();
install_extension()?;
initdb(postgresql_conf)?;

let system_session_id = start_pg(state.loglines.clone())?;
let pg_config = get_pg_config()?;
dropdb()?;
createdb(&pg_config, get_pg_dbname(), true, false, get_runas())?;
create_extension()?;
state.installed = true;
state.system_session_id = system_session_id;
initialize_test_framework(&mut state, postgresql_conf)
.expect("Could not initialize test framework");
}

Ok((state.loglines.clone(), state.system_session_id.clone()))
}

fn initialize_test_framework(
state: &mut SetupState,
postgresql_conf: Vec<&'static str>,
) -> eyre::Result<()> {
shutdown::register_shutdown_hook();
install_extension()?;
initdb(postgresql_conf)?;

let system_session_id = start_pg(state.loglines.clone())?;
let pg_config = get_pg_config()?;
dropdb()?;
createdb(&pg_config, get_pg_dbname(), true, false, get_runas())?;
create_extension()?;
state.installed = true;
state.system_session_id = system_session_id;
Ok(())
}

fn get_pg_config() -> eyre::Result<PgConfig> {
let pgrx = Pgrx::from_config().wrap_err("Unable to get PGRX from config")?;

Expand Down

0 comments on commit 4b32992

Please sign in to comment.