Files
go-sip/internal/store/current_control_test.go
T

50 lines
1.8 KiB
Go

package store
import (
"testing"
"time"
)
func TestCurrentStopSuppressesUnstartedCallsButPreservesUnknown(t *testing.T) {
s := preparedCurrentCallStore(t)
pending := currentCall("queued-before-stop")
if _, _, err := s.RecordExecute(pending); err != nil {
t.Fatal(err)
}
unknown := currentCall("unknown-before-stop")
if _, _, err := s.RecordExecute(unknown); err != nil {
t.Fatal(err)
}
if err := s.ReserveExecute(unknown.DispatcherID, unknown.EventID, currentReservation(), currentMondayUTC()); err != nil {
t.Fatal(err)
}
if err := s.MarkExecuteUnknown(unknown.DispatcherID, unknown.EventID); err != nil {
t.Fatal(err)
}
if err := s.ApplyControl(currentDispatcherID, 1001, "task-asr", "stop"); err != nil {
t.Fatal(err)
}
calls, err := s.ListPendingExecute(currentDispatcherID)
if err != nil || len(calls) != 0 {
t.Fatalf("stopped task still has dispatchable commands: %+v %v", calls, err)
}
var pendingStatus, unknownStatus string
if err := s.db.QueryRow(`SELECT status FROM dispatcher_inbox WHERE event_id=?`, pending.EventID).Scan(&pendingStatus); err != nil {
t.Fatal(err)
}
if err := s.db.QueryRow(`SELECT status FROM dispatcher_inbox WHERE event_id=?`, unknown.EventID).Scan(&unknownStatus); err != nil {
t.Fatal(err)
}
if pendingStatus != "suppressed" || unknownStatus != "unknown" {
t.Fatalf("stop did not preserve unknown and silently suppress unstarted: pending=%s unknown=%s", pendingStatus, unknownStatus)
}
if err := s.ApplyControl(currentDispatcherID, 1001, "task-asr", "resume"); err == nil {
t.Fatal("stopped task resumed")
}
if outbox, err := s.ListPendingOutbox(currentDispatcherID); err != nil || len(outbox) != 0 {
t.Fatalf("stop emitted per-call results: %+v %v", outbox, err)
}
}
func currentMondayUTC() time.Time { return time.Date(2026, 9, 21, 1, 30, 0, 0, time.UTC) }