summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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?",