mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-06-18 03:30:53 +00:00
41e6c8f5cc
- Tracing: recover stale running traces/spans on startup (PG + SQLite) - Browser: Chrome orphan cleanup via launcher PID, timeouts, Leakless - Claude CLI: WaitDelay 5s + context-cancel early exit - Agent loop: safety-net defer to finalize orphan root traces - UI: split workspace sharing into separate Memory and KG toggles - Minor: for-range idiom, min() builtin
69 lines
1.4 KiB
Go
69 lines
1.4 KiB
Go
package agent
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestParallelToolCollection_ContextCancel(t *testing.T) {
|
|
// Simulate: 3 tool calls, but ctx cancelled before all arrive
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
resultCh := make(chan indexedResult, 3)
|
|
|
|
// Send only 1 result, then cancel
|
|
resultCh <- indexedResult{idx: 0}
|
|
cancel()
|
|
|
|
collected := make([]indexedResult, 0, 3)
|
|
var err error
|
|
|
|
collectLoop:
|
|
for range 3 {
|
|
select {
|
|
case r, ok := <-resultCh:
|
|
if !ok {
|
|
break collectLoop
|
|
}
|
|
collected = append(collected, r)
|
|
case <-ctx.Done():
|
|
err = ctx.Err()
|
|
break collectLoop
|
|
}
|
|
}
|
|
|
|
if err == nil {
|
|
t.Fatal("expected context.Canceled error")
|
|
}
|
|
// We should have collected 1 result before cancellation (or 0 — timing dependent)
|
|
if len(collected) > 1 {
|
|
t.Errorf("expected at most 1 collected, got %d", len(collected))
|
|
}
|
|
}
|
|
|
|
func TestParallelToolCollection_AllComplete(t *testing.T) {
|
|
resultCh := make(chan indexedResult, 3)
|
|
resultCh <- indexedResult{idx: 0}
|
|
resultCh <- indexedResult{idx: 1}
|
|
resultCh <- indexedResult{idx: 2}
|
|
|
|
ctx := context.Background()
|
|
collected := make([]indexedResult, 0, 3)
|
|
|
|
collectLoop:
|
|
for range 3 {
|
|
select {
|
|
case r, ok := <-resultCh:
|
|
if !ok {
|
|
break collectLoop
|
|
}
|
|
collected = append(collected, r)
|
|
case <-ctx.Done():
|
|
t.Fatal("context should not be cancelled")
|
|
}
|
|
}
|
|
|
|
if len(collected) != 3 {
|
|
t.Fatalf("expected 3, got %d", len(collected))
|
|
}
|
|
}
|