50 lines
1.7 KiB
Go
50 lines
1.7 KiB
Go
package store
|
|
|
|
import (
|
|
"testing"
|
|
|
|
agentv1 "git.ipao.vip/rogee/go-sip/gen/agent/v1"
|
|
"git.ipao.vip/rogee/go-sip/internal/contract"
|
|
"git.ipao.vip/rogee/go-sip/internal/testfixture"
|
|
)
|
|
|
|
func TestExecutionRouteRequiresReservedMatchingTask(t *testing.T) {
|
|
s := testStore(t)
|
|
raw, err := testfixture.Execute()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
envelope, payload, err := contract.DecodeExecute(raw)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := s.IngestCommand(raw, testfixture.InboundKey(envelope.TenantKey)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
binding := &agentv1.ExecutionBinding{TenantId: envelope.TenantID, TenantKey: envelope.TenantKey, TaskId: payload.TaskID, TaskItemId: payload.TaskItemID, TaskRevision: payload.TaskRevision, ExecutionId: payload.ExecutionID, AgentVersionId: payload.AgentVersionID, RoutePolicyId: payload.RoutePolicyID, CallerProfileId: payload.CallerProfileID}
|
|
if err := s.BindExecutionAgent("agent-a", binding); err == nil {
|
|
t.Fatal("unreserved task dispatched")
|
|
}
|
|
if err := s.SetQuota("global", 1); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := s.Reserve("reservation-a", binding.ExecutionId, binding.TenantKey, []string{"global"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := s.BindExecutionAgent("agent-a", binding); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := s.BindExecutionAgent("agent-a", binding); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := s.BindExecutionAgent("other-agent", binding); err == nil {
|
|
t.Fatal("execution reassigned to another agent")
|
|
}
|
|
if _, err := s.DB().Exec(`UPDATE tasks SET status='paused'`); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := s.BindExecutionAgent("agent-a", binding); err == nil {
|
|
t.Fatal("existing route bypassed pause barrier")
|
|
}
|
|
}
|