test: clean up config-owned fabro daemons

This commit is contained in:
Bryan Helmkamp 2026-04-05 12:59:20 -04:00
parent 48c9db2909
commit 7952b336a9
2 changed files with 22 additions and 5 deletions

View file

@ -187,9 +187,10 @@ SHARED = "run"
/// Set up an external workflow fixture with a custom storage_dir in user.toml.
/// Returns (project_tempdir, storage_dir_path).
fn setup_external_workflow_fixture(
context: &fabro_test::TestContext,
context: &mut fabro_test::TestContext,
) -> (tempfile::TempDir, PathBuf) {
let storage_dir = context.home_dir.join("fabro-data");
context.manage_storage_dir(&storage_dir);
context.write_home(
".fabro/user.toml",
@ -369,8 +370,8 @@ fn settings_workflow_name_applies_run_overlay_and_deep_merges() {
#[test]
fn settings_explicit_workflow_path_uses_workflow_project_layers() {
let context = test_context!();
let (project, _storage_dir) = setup_external_workflow_fixture(&context);
let mut context = test_context!();
let (project, _storage_dir) = setup_external_workflow_fixture(&mut context);
let cwd = tempfile::tempdir().unwrap();
let workflow = project.path().join("workflow.toml");
@ -404,8 +405,8 @@ fn settings_explicit_workflow_path_uses_workflow_project_layers() {
#[test]
fn create_explicit_workflow_path_uses_project_config_relative_to_workflow() {
let context = test_context!();
let (project, storage_dir) = setup_external_workflow_fixture(&context);
let mut context = test_context!();
let (project, storage_dir) = setup_external_workflow_fixture(&mut context);
let cwd = tempfile::tempdir().unwrap();
let workflow = project.path().join("workflow.toml");
let run_id = unique_run_id();

View file

@ -103,6 +103,7 @@ pub struct TestContext {
session_root: PathBuf,
fabro_bin: PathBuf,
filters: Vec<(String, String)>,
managed_storage_dirs: Vec<PathBuf>,
_context_root: tempfile::TempDir,
}
@ -440,6 +441,7 @@ impl TestContext {
session_root: session_paths.root,
fabro_bin,
filters,
managed_storage_dirs: Vec::new(),
_context_root: context_root,
}
}
@ -678,6 +680,16 @@ impl TestContext {
self
}
/// Register an additional storage directory that this test may cause to
/// auto-start a daemon for, so Drop can stop it.
pub fn manage_storage_dir(&mut self, path: impl AsRef<Path>) -> &mut Self {
let path = path.as_ref().to_path_buf();
if path != self.storage_dir && !self.managed_storage_dirs.contains(&path) {
self.managed_storage_dirs.push(path);
}
self
}
/// Find a run directory whose name ends with `run_id_suffix`.
pub fn find_run_dir(&self, run_id_suffix: &str) -> PathBuf {
let runs_dir = self.storage_dir.join("runs");
@ -737,6 +749,10 @@ impl TestContext {
impl Drop for TestContext {
fn drop(&mut self) {
for storage_dir in &self.managed_storage_dirs {
stop_session_server(&self.fabro_bin, storage_dir);
}
let is_last_ref = {
let mut refs = session_refs().lock().expect("session refs lock poisoned");
let Some(count) = refs.get_mut(&self.session_root) else {