diff --git a/pgrx-tests/src/framework.rs b/pgrx-tests/src/framework.rs index 83b009427..abcf7b815 100644 --- a/pgrx-tests/src/framework.rs +++ b/pgrx-tests/src/framework.rs @@ -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()?; @@ -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 { @@ -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 { let pgrx = Pgrx::from_config().wrap_err("Unable to get PGRX from config")?;