feat(bus): tines-bus transport and daemon over a host IPC bus

This commit is contained in:
2026-10-24 23:00:37 -07:00
parent 01373d809d
commit ee87808b05
10 changed files with 1036 additions and 1 deletions
+34
View File
@@ -0,0 +1,34 @@
//! Shared helpers for the tines-bus integration tests.
#![allow(dead_code)]
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicUsize, Ordering};
static COUNTER: AtomicUsize = AtomicUsize::new(0);
/// A fresh, unique scratch directory under the system temp dir.
pub fn unique_dir(tag: &str) -> PathBuf {
let n = COUNTER.fetch_add(1, Ordering::Relaxed);
let dir = std::env::temp_dir().join(format!("tines-bus-{tag}-{}-{n}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
dir
}
/// Spawn the bus daemon on a thread and return its socket path once bound.
pub fn spawn_daemon(dir: &Path) -> PathBuf {
let sock = dir.join("bus.sock");
let s = sock.clone();
std::thread::spawn(move || {
if let Err(e) = tines_bus::daemon::serve(&s) {
panic!("daemon failed: {e}");
}
});
// Wait for the daemon to bind, so the first connect cannot race it.
for _ in 0..400 {
if sock.exists() {
return sock;
}
std::thread::sleep(std::time::Duration::from_millis(5));
}
panic!("daemon did not bind in time");
}