use std::time::{Duration, Instant};
use std::thread;
pub fn run_with_timeout<F>(timeout: Duration, name: &str, f: F)
where
F: FnOnce() + Send + 'static,
{
println!("\n=== Test: {} (timeout: {:?}) ===", name, timeout);
let handle = thread::spawn(f);
let start = Instant::now();
while start.elapsed() < timeout {
if handle.is_finished() {
return;
}
thread::sleep(Duration::from_millis(10));
}
println!("⏱️ Test timed out after {:?} - skipping", timeout);
}
pub fn should_run_live_tests() -> bool {
std::env::var("RILL_TEST_LIVE_AUDIO").is_ok()
}
pub fn test_config() -> crate::AudioConfig {
crate::AudioConfig::default()
.with_sample_rate(44100)
.with_buffer_size(256)
.with_channels(2)
}
pub fn silence_alsa() {
std::env::set_var("ALSA_CONFIG_PATH", "/dev/null");
}
pub fn silence_all_audio() {
#[cfg(target_os = "linux")]
{
silence_alsa();
}
}