MCPcopy Create free account
hub / github.com/compozy/agh / TestManagerEnqueueRunRejectsConcurrentOpenRun

Function TestManagerEnqueueRunRejectsConcurrentOpenRun

internal/task/manager_test.go:4089–4186  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4087}
4088
4089func TestManagerEnqueueRunRejectsConcurrentOpenRun(t *testing.T) {
4090 t.Parallel()
4091
4092 tests := []struct {
4093 name string
4094 openRun func(context.Context, *testing.T, *Service, Run, ActorContext) Run
4095 wantOpen RunStatus
4096 }{
4097 {
4098 name: "queued",
4099 openRun: func(_ context.Context, _ *testing.T, _ *Service, run Run, _ ActorContext) Run {
4100 return run
4101 },
4102 wantOpen: TaskRunStatusQueued,
4103 },
4104 {
4105 name: "running",
4106 openRun: func(ctx context.Context, t *testing.T, manager *Service, run Run, actor ActorContext) Run {
4107 t.Helper()
4108 claimed, err := manager.ClaimRun(ctx, run.ID, ClaimRun{}, actor)
4109 if err != nil {
4110 t.Fatalf("ClaimRun() error = %v", err)
4111 }
4112 running, err := manager.StartRun(ctx, claimed.ID, StartRun{}, actor)
4113 if err != nil {
4114 t.Fatalf("StartRun() error = %v", err)
4115 }
4116 return *running
4117 },
4118 wantOpen: TaskRunStatusRunning,
4119 },
4120 }
4121
4122 for _, tt := range tests {
4123 t.Run(tt.name, func(t *testing.T) {
4124 t.Parallel()
4125
4126 ctx := context.Background()
4127 store := newInMemoryManagerStore()
4128 manager := newTaskManagerForTestWithOptions(
4129 t,
4130 store,
4131 WithSessionExecutor(testSessionExecutor{}),
4132 )
4133 actor := validActorContext()
4134
4135 taskRecord, err := manager.CreateTask(ctx, CreateTask{
4136 Scope: ScopeGlobal,
4137 Title: "Concurrent run guard",
4138 }, actor)
4139 if err != nil {
4140 t.Fatalf("CreateTask() error = %v", err)
4141 }
4142
4143 firstRun, err := manager.EnqueueRun(ctx, EnqueueRun{
4144 TaskID: taskRecord.ID,
4145 IdempotencyKey: "same-logical-run",
4146 }, actor)

Callers

nothing calls this directly

Calls 12

newInMemoryManagerStoreFunction · 0.85
WithSessionExecutorFunction · 0.85
validActorContextFunction · 0.85
ClaimRunMethod · 0.65
StartRunMethod · 0.65
RunMethod · 0.65
CreateTaskMethod · 0.65
EnqueueRunMethod · 0.65
ListTaskRunsMethod · 0.65
NormalizeMethod · 0.45
IsMethod · 0.45

Tested by

no test coverage detected