mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-06-24 06:49:59 +02:00
41 lines
945 B
Go
41 lines
945 B
Go
package handler
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestAbortActiveEinoExecute(t *testing.T) {
|
|
m := NewAgentTaskManager()
|
|
conv := "conv-eino-exec-abort"
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
_, err := m.StartTask(conv, "test", func(error) {})
|
|
if err != nil {
|
|
t.Fatalf("StartTask: %v", err)
|
|
}
|
|
m.RegisterActiveEinoExecute(conv, cancel)
|
|
|
|
done := make(chan struct{})
|
|
go func() {
|
|
<-ctx.Done()
|
|
close(done)
|
|
}()
|
|
|
|
if !m.AbortActiveEinoExecute(conv, "跳过域名收集") {
|
|
t.Fatal("expected abort to succeed")
|
|
}
|
|
select {
|
|
case <-done:
|
|
case <-time.After(2 * time.Second):
|
|
t.Fatal("execute cancel did not propagate")
|
|
}
|
|
if got := m.TakeEinoExecuteAbortNote(conv); got != "跳过域名收集" {
|
|
t.Fatalf("abort note = %q, want 跳过域名收集", got)
|
|
}
|
|
m.UnregisterActiveEinoExecute(conv)
|
|
if m.AbortActiveEinoExecute(conv, "") {
|
|
t.Fatal("second abort should fail when no active execute")
|
|
}
|
|
}
|