Files
artex/server/engine_llm_calls_test.go
T
dela 0335d572de
ci / go (push) Waiting to run
ci / go-db (agent) (push) Waiting to run
ci / go-db (config) (push) Waiting to run
ci / go-db (db) (push) Waiting to run
ci / go-db (evidence) (push) Waiting to run
ci / go-db (llmrec) (push) Waiting to run
ci / go-db (server) (push) Waiting to run
detections / detections (push) Waiting to run
web / web (push) Waiting to run
docs / links (push) Canceled after 0s
First Commit
2026-10-09 08:38:16 +08:00

44 lines
931 B
Go

package server
import (
"sync"
"testing"
)
func TestEngineActiveLLMCallsConcurrent(t *testing.T) {
e := NewEngine(nil)
const taskID = "42"
const calls = 64
var started sync.WaitGroup
var release sync.WaitGroup
var finished sync.WaitGroup
started.Add(calls)
finished.Add(calls)
release.Add(1)
for range calls {
go func() {
defer finished.Done()
e.BeginLLMCall(taskID)
started.Done()
release.Wait()
e.EndLLMCall(taskID)
}()
}
started.Wait()
if got := e.ActiveLLMCalls(taskID); got != calls {
t.Fatalf("active calls = %d, want %d", got, calls)
}
release.Done()
finished.Wait()
if got := e.ActiveLLMCalls(taskID); got != 0 {
t.Fatalf("active calls after completion = %d, want 0", got)
}
// A defensive extra end must never expose a negative UI count.
e.EndLLMCall(taskID)
if got := e.ActiveLLMCalls(taskID); got != 0 {
t.Fatalf("active calls after extra end = %d, want 0", got)
}
}