summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Otto <th1000s@posteo.net>2022-01-03 21:49:53 +0100
committerDan Davison <dandavison7@gmail.com>2022-01-03 17:28:27 -0500
commit59604a376f6aaf8d4b146d11a863597aa2e6e814 (patch)
tree2286fc9f977617341c693f04e32e52e0d2cc5753
parentc1392d6e1cc8bb21dd8e59c4226f6d9154e1844e (diff)
Cache parent process when testing unless FakeParentArgs are used
-rw-r--r--src/utils/process.rs19
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?",