45 lines
1.8 KiB
Go
45 lines
1.8 KiB
Go
package store
|
|
|
|
import (
|
|
"errors"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.ipao.vip/rogee/go-sip/internal/configread"
|
|
)
|
|
|
|
func TestStructuralRejectionCannotMislabelAlreadyAdmittedExecution(t *testing.T) {
|
|
s, err := Open(filepath.Join(t.TempDir(), "state.db"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer s.Close()
|
|
snapshot := currentStoreSnapshot(t)
|
|
if err := s.ApplyDiscoverySnapshot(currentDispatcherID, []configread.DiscoveredTask{{TaskID: snapshot.Task.TaskID, TenantID: snapshot.Task.TenantID, TaskRevision: 1, Status: "running"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := s.SaveSnapshot(snapshot); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cmd := ExecuteCommand{DispatcherID: currentDispatcherID, TenantID: 1001, EventID: "admitted-original", TaskID: snapshot.Task.TaskID, Callee: "15003164745", IssuedAt: time.Date(2026, 10, 5, 12, 0, 0, 0, time.UTC).Format(time.RFC3339Nano)}
|
|
if _, _, err := s.RecordExecute(cmd); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := s.db.Exec(`UPDATE dispatcher_inbox SET status='unknown' WHERE dispatcher_id=? AND event_id=?`, cmd.DispatcherID, cmd.EventID); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
raw := []byte(`{"event_id":"admitted-original","event_type":"call.execute","dispatcher_id":"` + currentDispatcherID + `","tenant_id":1001,"payload":{}}`)
|
|
if err := s.RejectData(currentDispatcherID, raw, errors.New("issued_at required")); err == nil {
|
|
t.Fatal("structural rejection contradicted an admitted execution")
|
|
}
|
|
var status string
|
|
if err := s.db.QueryRow(`SELECT status FROM dispatcher_inbox WHERE dispatcher_id=? AND event_id=?`, cmd.DispatcherID, cmd.EventID).Scan(&status); err != nil || status != "unknown" {
|
|
t.Fatalf("unknown execution changed: %s %v", status, err)
|
|
}
|
|
events, err := s.ListPendingOutbox(currentDispatcherID)
|
|
if err != nil || len(events) != 0 {
|
|
t.Fatalf("false rejection published: %+v %v", events, err)
|
|
}
|
|
}
|