Skip to content

Commit

Permalink
clear OMDB_ environment variables when running omdb tests (#6368)
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco authored Aug 16, 2024
1 parent 6bb3c13 commit c86ff79
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions dev-tools/omdb/tests/test_all_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fn assert_oximeter_list_producers_output(

#[tokio::test]
async fn test_omdb_usage_errors() {
clear_omdb_env();
let cmd_path = path_to_executable(CMD_OMDB);
let mut output = String::new();
let invocations: &[&[&'static str]] = &[
Expand Down Expand Up @@ -111,6 +112,8 @@ async fn test_omdb_usage_errors() {

#[nexus_test]
async fn test_omdb_success_cases(cptestctx: &ControlPlaneTestContext) {
clear_omdb_env();

let gwtestctx = gateway_test_utils::setup::test_setup(
"test_omdb_success_case",
gateway_messages::SpPort::One,
Expand Down Expand Up @@ -271,6 +274,8 @@ async fn test_omdb_success_cases(cptestctx: &ControlPlaneTestContext) {
/// that's covered by the success tests above.
#[nexus_test]
async fn test_omdb_env_settings(cptestctx: &ControlPlaneTestContext) {
clear_omdb_env();

let cmd_path = path_to_executable(CMD_OMDB);
let postgres_url = cptestctx.database.listen_url().to_string();
let nexus_internal_url =
Expand Down Expand Up @@ -504,3 +509,22 @@ async fn do_run_extra<F>(

write!(output, "=============================================\n").unwrap();
}

// We're testing behavior that can be affected by OMDB-related environment
// variables. Clear all of them from the current process so that all child
// processes don't have them. OMDB environment variables can affect even the
// help output provided by clap. See clap-rs/clap#5673 for an example.
fn clear_omdb_env() {
// Rust documents that it's not safe to manipulate the environment in a
// multi-threaded process outside of Windows because it's possible that
// other threads are reading or writing the environment and most systems do
// not support this. On illumos, the underlying interfaces are broadly
// thread-safe. Further, Omicron only supports running tests under `cargo
// nextest`, in which case there are no threads running concurrently here
// that may be reading or modifying the environment.
for (env_var, _) in std::env::vars().filter(|(k, _)| k.starts_with("OMDB_"))
{
eprintln!("removing {:?} from environment", env_var);
std::env::remove_var(env_var);
}
}
1 change: 1 addition & 0 deletions nexus/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

//! Integration testing facilities for Nexus
#[cfg(feature = "omicron-dev")]
use anyhow::Context;
use anyhow::Result;
use camino::Utf8Path;
Expand Down

0 comments on commit c86ff79

Please sign in to comment.