返回 DeepSeek-Reasonix
temphelper_test.go
根目录 / internal / boot / temphelper_test.go
1 package boot
2
3 import (
4 "os"
5 "testing"
6 "time"
7 )
8
9 // robustTempDir is a drop-in for t.TempDir whose cleanup retries RemoveAll for a
10 // short window. Tests here build a full Controller (Build / control.New); at
11 // teardown a background resource — a job goroutine draining after its context is
12 // cancelled, or an MCP stats/schema writer flushing — can still hold a file
13 // under the dir for a few milliseconds after Close returns. On Windows that
14 // surfaces as "being used by another process"; on Linux a write racing RemoveAll
15 // surfaces as "directory not empty". Plain t.TempDir turns that teardown race
16 // into a red test even though every assertion passed (this is the recurring
17 // main-v2 CI flake that #3371 only papered over). Retrying absorbs the race; a
18 // dir that never frees is logged, not fatal, so a genuine leak stays visible
19 // without reintroducing the flake.
20 func robustTempDir(t *testing.T) string {
21 t.Helper()
22 dir, err := os.MkdirTemp("", "reasonix-test-*")
23 if err != nil {
24 t.Fatalf("robustTempDir: %v", err)
25 }
26 t.Cleanup(func() {
27 var rmErr error
28 for i := 0; i < 100; i++ {
29 if rmErr = os.RemoveAll(dir); rmErr == nil {
30 return
31 }
32 time.Sleep(20 * time.Millisecond)
33 }
34 t.Logf("robustTempDir: cleanup did not converge for %s: %v", dir, rmErr)
35 })
36 return dir
37 }
38
38 lines GO