(t *testing.T)
| 4087 | } |
| 4088 | |
| 4089 | func 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) |
nothing calls this directly
no test coverage detected