diff options
author | Thomas Otto <th1000s@posteo.net> | 2022-01-03 21:49:53 +0100 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2022-01-03 17:28:27 -0500 |
commit | 59604a376f6aaf8d4b146d11a863597aa2e6e814 (patch) | |
tree | 2286fc9f977617341c693f04e32e52e0d2cc5753 /src/utils/process.rs | |
parent | c1392d6e1cc8bb21dd8e59c4226f6d9154e1844e (diff) |
Cache parent process when testing unless FakeParentArgs are used
Diffstat (limited to 'src/utils/process.rs')
-rw-r--r-- | src/utils/process.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/utils/process.rs b/src/utils/process.rs index cc75e31c..f111e9d4 100644 --- a/src/utils/process.rs +++ b/src/utils/process.rs @@ -62,7 +62,21 @@ pub fn calling_process() -> MutexGuard<'static, CallingProcess> { #[cfg(test)] pub fn calling_process() -> Box<CallingProcess> { type _UnusedImport = MutexGuard<'static, i8>; - Box::new(determine_calling_process()) + + if crate::utils::process::tests::FakeParentArgs::are_set() { + // If the (thread-local) FakeParentArgs are set, then the following command returns + // these, so the cached global real ones can not be used. + Box::new(determine_calling_process()) + } else { + let (caller_mutex, _) = &**CALLER; + + let mut caller = caller_mutex.lock().unwrap(); + if *caller == CallingProcess::Pending { + *caller = determine_calling_process(); + } + + Box::new(caller.clone()) + } } fn determine_calling_process() -> CallingProcess { @@ -589,6 +603,9 @@ pub mod tests { } }) } + pub fn are_set() -> bool { + FAKE_ARGS.with(|a| *a.borrow() != TlsState::None) + } fn error(where_: &str) -> ! { panic!( "test logic error (in {}): wrong FakeParentArgs scope?", |