返回 DeepSeek-Reasonix
index_queue_test.go
根目录 / internal / sessioncatalog / index_queue_test.go
1 package sessioncatalog
2
3 import (
4 "fmt"
5 "path/filepath"
6 "testing"
7 )
8
9 func TestTryIndexQueueOverflowDoesNotEnterJournalWriter(t *testing.T) {
10 c := &Catalog{opts: Options{MetadataOnly: true}, pathCh: make(chan sessionPathRequest, 1), stop: make(chan struct{})}
11 root := t.TempDir()
12 target := DirectoryTarget{Path: root, Scope: "global"}
13 first := filepath.Join(root, "first.jsonl")
14 if !c.TryRequestIndexSession(target, first) {
15 t.Fatal("first path rejected")
16 }
17 // No worker or database is present. Hold the writer boundary to prove a
18 // burst can always be consumed even while SQLite publication is blocked.
19 c.mutationMu.Lock()
20 defer c.mutationMu.Unlock()
21 for i := range 4096 {
22 if c.TryRequestIndexSession(target, filepath.Join(root, fmt.Sprintf("%d.jsonl", i))) {
23 t.Fatal("overflow unexpectedly admitted")
24 }
25 }
26 if !c.TryRequestIndexSession(DirectoryTarget{Path: root, Scope: "project", WorkspaceRoot: root}, first) {
27 t.Fatal("queued identity must still coalesce when full")
28 }
29 count := 0
30 c.pathQueued.Range(func(_, value any) bool {
31 count++
32 if value.(sessionPathRequest).target.Scope != "project" {
33 t.Fatal("coalescing lost newest target")
34 }
35 return true
36 })
37 if count != 1 || len(c.pathCh) != 1 {
38 t.Fatalf("overflow grew the retained queue: paths=%d signals=%d", count, len(c.pathCh))
39 }
40 }
41
41 lines GO