From 880dcc5b641ac2988d697a0132ce484d86ee4733 Mon Sep 17 00:00:00 2001 From: esengine <359807859@qq.com> Date: Sat, 3 Oct 2026 16:11:28 -0700 Subject: [PATCH] test(boot): close process-global catalogs before the temp dir is removed testenv.TempDir retries RemoveAll for two seconds when a file stays held. On Windows the usage and history SQLite catalogs, which the shared helpers left open, held a file under nearly every test's directory, so each of those tests paid the full retry budget at teardown. Closing the catalogs from the helper's own cleanup, which runs before the removal, makes it converge on the first attempt. --- internal/assembly/boot/config_home_test.go | 4 ++++ internal/assembly/boot/temphelper_test.go | 11 ++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/assembly/boot/config_home_test.go b/internal/assembly/boot/config_home_test.go index bfaeda3371..e3d7b75ec5 100644 --- a/internal/assembly/boot/config_home_test.go +++ b/internal/assembly/boot/config_home_test.go @@ -9,6 +9,7 @@ import ( "reasonix/internal/state/history" "reasonix/internal/state/historycatalog" + "reasonix/internal/state/stats" ) // isolateConfigHome redirects user config and cache paths to a per-test temp @@ -36,6 +37,9 @@ func closeBootTestHistoryCatalog(t *testing.T) { if err := history.CloseSharedCatalog(ctx); err != nil { t.Fatalf("close shared history catalog: %v", err) } + if err := stats.CloseUsageCatalogs(ctx); err != nil { + t.Fatalf("close usage catalogs: %v", err) + } } // fenceBootTestHistoryCatalog releases a process-global projection inherited diff --git a/internal/assembly/boot/temphelper_test.go b/internal/assembly/boot/temphelper_test.go index 9339defc02..3243539ce9 100644 --- a/internal/assembly/boot/temphelper_test.go +++ b/internal/assembly/boot/temphelper_test.go @@ -6,11 +6,12 @@ import ( "reasonix/internal/base/testenv" ) -// robustTempDir is the name boot's call sites already use for testenv.TempDir, -// whose cleanup retries RemoveAll. Teardown here can leave a job goroutine or an -// MCP writer holding a file for a few milliseconds after Close returns, which -// plain t.TempDir turns into a red test with every assertion passed. +// robustTempDir is testenv.TempDir, whose cleanup retries RemoveAll for +// handles that outlive Close by milliseconds. The process-global catalogs are +// closed first: an open SQLite file outlasts every retry on Windows. func robustTempDir(t *testing.T) string { t.Helper() - return testenv.TempDir(t) + dir := testenv.TempDir(t) + t.Cleanup(func() { closeBootTestHistoryCatalog(t) }) + return dir }