//! Starting `memoryd` for the device tests, with the repository's starter `soul.md`: `loopd` //! starts no session without the memory block. Do not edit. use std::path::Path; use std::process::{Child, Command}; use std::thread; use std::time::Duration; /// Write `memoryd.toml` into `home`, start `memoryd serve`, and wait for its `loopd` socket. pub fn start(home: &Path) -> Child { let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../.."); let config = home.join("memoryd.toml"); std::fs::write( &config, format!( "[paths]\nhome = \"{}\"\n[memory]\nsoul_starter = \"{}\"\n", home.display(), root.join("config/soul.md").display() ), ) .unwrap(); let socket = home.join("run").join("loop-memory").join("memory.sock"); let _ = std::fs::remove_file(&socket); let bin = std::env::var("BOXMAKER_MEMORYD").expect("BOXMAKER_MEMORYD is not set"); let mut child = Command::new(bin) .arg("serve") .arg("--config") .arg(&config) .spawn() .expect("cannot start memoryd"); for _ in 0..600 { if socket.exists() { return child; } thread::sleep(Duration::from_millis(100)); } let _ = child.kill(); let _ = child.wait(); panic!("memoryd did not come up within 60 s"); }