use std::path::PathBuf;
use std::sync::{Mutex, OnceLock};
use std::time::Duration;
#[cfg(any(windows, target_os = "macos"))]
use tokio::sync::{Semaphore, SemaphorePermit};
#[cfg(any(windows, target_os = "macos"))]
const RESOURCE_INTENSIVE_TEST_CONCURRENCY: usize = 1;
#[cfg(any(windows, target_os = "macos"))]
pub(crate) async fn resource_intensive_test_permit() -> SemaphorePermit<'static> {
static PERMITS: OnceLock<Semaphore> = OnceLock::new();
PERMITS
.get_or_init(|| Semaphore::new(RESOURCE_INTENSIVE_TEST_CONCURRENCY))
.acquire()
.await
.expect("resource-intensive test semaphore must remain open")
}
#[cfg(not(any(windows, target_os = "macos")))]
pub(crate) async fn resource_intensive_test_permit() {}
pub(crate) fn hermetic_workspace() -> PathBuf {
static KEEP: OnceLock<Mutex<Vec<tempfile::TempDir>>> = OnceLock::new();
let dir = tempfile::tempdir().expect("hermetic workspace");
let path = dir.path().to_path_buf();
KEEP.get_or_init(|| Mutex::new(Vec::new()))
.lock()
.expect("hermetic workspace lock")
.push(dir);
path
}
pub(crate) const fn external_resource_start_timeout(default: Duration) -> Duration {
#[cfg(any(windows, target_os = "macos"))]
{
if default.as_secs() < 30 {
return Duration::from_secs(30);
}
}
default
}