返回 DeepSeek-Reasonix
session_listing_repair_lock_test.go
根目录 / internal / agent / session_listing_repair_lock_test.go
1 package agent
2
3 import (
4 "context"
5 "errors"
6 "path/filepath"
7 "testing"
8 "time"
9
10 "reasonix/internal/provider"
11 )
12
13 func TestRepairSessionListingProjectionDoesNotWaitForMetaLock(t *testing.T) {
14 path := filepath.Join(t.TempDir(), "meta-busy.jsonl")
15 writeSessionFile(t, path, []provider.Message{{Role: provider.RoleUser, Content: "question"}})
16 unlockMeta, err := LockSessionMetaPath(path)
17 if err != nil {
18 t.Fatal(err)
19 }
20 defer unlockMeta()
21
22 repairResult := make(chan error, 1)
23 go func() {
24 _, repairErr := RepairSessionListingProjection(context.Background(), path)
25 repairResult <- repairErr
26 }()
27 select {
28 case err = <-repairResult:
29 case <-time.After(5 * time.Second):
30 t.Fatal("meta-busy repair did not yield to the foreground owner")
31 }
32 if !errors.Is(err, ErrSessionListingRepairBusy) {
33 t.Fatalf("repair err = %v, want busy", err)
34 }
35
36 unlockSave, ok := tryLockSessionSavePath(path)
37 if !ok {
38 t.Fatal("repair retained the foreground save lock after yielding")
39 }
40 unlockSave()
41 unlockFile, err := tryLockSessionFile(path)
42 if err != nil {
43 t.Fatalf("repair retained the compatibility file lock after yielding: %v", err)
44 }
45 unlockFile()
46 }
47
47 lines GO