1
//! Shared fixtures for xtask's unit tests.
2

            
3
use std::sync::{Mutex, MutexGuard, PoisonError};
4

            
5
static PROCESSES: Mutex<()> = Mutex::new(());
6

            
7
/// Held by every test that starts a process. A test that writes a script and
8
/// then runs it fails with ETXTBSY when another test forks while the script is
9
/// still open for writing, because the forked child keeps that descriptor
10
/// until its own exec. Serialising process-starting tests closes that window.
11
19
pub fn processes() -> MutexGuard<'static, ()> {
12
19
    PROCESSES.lock().unwrap_or_else(PoisonError::into_inner)
13
19
}