GitHub Actions Security / actionlint (pull_request) Failing after 46s
Rust CI / cargo fmt (pull_request) Successful in 36s
Rust CI / cargo clippy (pull_request) Failing after 41s
Rust CI / cargo doc (pull_request) Successful in 46s
Netem Interop / netem interop (pull_request) Failing after 40s
Supply chain / cargo-deny advisories (pull_request) Failing after 8s
Supply chain / cargo-deny bans licenses sources (pull_request) Failing after 8s
GitHub Actions Security / zizmor (pull_request) Failing after 3m46s
Proto Fuzz Smoke / cargo fuzz smoke (pull_request) Successful in 2m0s
Supply chain / actionlint (pull_request) Failing after 45s
Rust CI / cargo check (x86_64-unknown-linux-gnu) (pull_request) Canceled after 0s
Rust CI / cargo test (x86_64-unknown-linux-gnu) (pull_request) Canceled after 0s
Rust CI / cargo check (aarch64-unknown-linux-gnu) (pull_request) Canceled after 0s
Rust CI / cargo test (aarch64-unknown-linux-gnu) (pull_request) Canceled after 0s
Rust CI / cargo check (x86_64-unknown-linux-musl) (pull_request) Canceled after 0s
Rust CI / cargo test (x86_64-unknown-linux-musl) (pull_request) Canceled after 0s
Rust CI / cargo check (aarch64-unknown-linux-musl) (pull_request) Canceled after 0s
Rust CI / cargo test (aarch64-unknown-linux-musl) (pull_request) Canceled after 0s
Release / plan (pull_request) Canceled after 0s
Release / build-local-artifacts (${{ join(matrix.targets, ', ') }}) (pull_request) Canceled after 0s
Release / build-global-artifacts (pull_request) Canceled after 0s
Release / host (pull_request) Canceled after 0s
Release / announce (pull_request) Canceled after 0s
Enable configuration via IRTT_SERVER_* environment variables to simplify deployments in containerized or orchestrated environments. This adds the clap "env" feature and includes thread-safe tests to verify variable precedence.
31 lines
1.1 KiB
Rust
31 lines
1.1 KiB
Rust
//! Serializes every test in this module tree that touches process
|
|
//! environment variables.
|
|
//!
|
|
//! `ServerArgs` parsing reads `IRTT_SERVER_*` via `clap`'s `env` support, and
|
|
//! `std::env::set_var`/`remove_var` mutate genuinely process-wide state.
|
|
//! Every test that parses `ServerArgs` — whether or not it sets an env var
|
|
//! itself — must go through [`with_env_lock`], or a parse in one test thread
|
|
//! can observe a value another thread's test set only for the duration of
|
|
//! its own assertions. Reentrant per-thread, since a test that sets env vars
|
|
//! typically calls `parse` again from inside its own locked section.
|
|
|
|
use std::{cell::Cell, sync::Mutex};
|
|
|
|
static ENV_LOCK: Mutex<()> = Mutex::new(());
|
|
thread_local! {
|
|
static ENV_LOCK_HELD: Cell<bool> = const { Cell::new(false) };
|
|
}
|
|
|
|
pub(crate) fn with_env_lock<T>(f: impl FnOnce() -> T) -> T {
|
|
if ENV_LOCK_HELD.with(Cell::get) {
|
|
return f();
|
|
}
|
|
let _guard = ENV_LOCK
|
|
.lock()
|
|
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
|
ENV_LOCK_HELD.with(|held| held.set(true));
|
|
let result = f();
|
|
ENV_LOCK_HELD.with(|held| held.set(false));
|
|
result
|
|
}
|