|
11 | 11 | use Tests\TestCase; |
12 | 12 | use Workflow\Serializers\CodecRegistry; |
13 | 13 | use Workflow\Serializers\Serializer; |
| 14 | +use Workflow\V2\Contracts\MatchingRole; |
14 | 15 | use Workflow\V2\Enums\RunStatus; |
15 | 16 | use Workflow\V2\Enums\SignalStatus; |
16 | 17 | use Workflow\V2\Enums\TaskStatus; |
@@ -172,6 +173,103 @@ public function testItReportsExistingTaskRecoveryCountsInHumanOutput(): void |
172 | 173 | ); |
173 | 174 | } |
174 | 175 |
|
| 176 | + public function testItUsesTheMatchingRoleBindingForRepairPasses(): void |
| 177 | + { |
| 178 | + $fake = new class() implements MatchingRole { |
| 179 | + /** |
| 180 | + * @var array{connection: string|null, queue: string|null, respectThrottle: bool, runIds: list<string>, instanceId: string|null}|null |
| 181 | + */ |
| 182 | + public ?array $lastRunPassArguments = null; |
| 183 | + |
| 184 | + public function wake(?string $connection = null, ?string $queue = null): void |
| 185 | + { |
| 186 | + } |
| 187 | + |
| 188 | + public function runPass( |
| 189 | + ?string $connection = null, |
| 190 | + ?string $queue = null, |
| 191 | + bool $respectThrottle = false, |
| 192 | + array $runIds = [], |
| 193 | + ?string $instanceId = null, |
| 194 | + ): array { |
| 195 | + $this->lastRunPassArguments = [ |
| 196 | + 'connection' => $connection, |
| 197 | + 'queue' => $queue, |
| 198 | + 'respectThrottle' => $respectThrottle, |
| 199 | + 'runIds' => $runIds, |
| 200 | + 'instanceId' => $instanceId, |
| 201 | + ]; |
| 202 | + |
| 203 | + return [ |
| 204 | + 'connection' => $connection, |
| 205 | + 'queue' => $queue, |
| 206 | + 'run_ids' => $runIds, |
| 207 | + 'instance_id' => $instanceId, |
| 208 | + 'respect_throttle' => $respectThrottle, |
| 209 | + 'throttled' => false, |
| 210 | + 'selected_existing_task_candidates' => 0, |
| 211 | + 'selected_missing_task_candidates' => 0, |
| 212 | + 'selected_total_candidates' => 0, |
| 213 | + 'repaired_existing_tasks' => 0, |
| 214 | + 'repaired_missing_tasks' => 0, |
| 215 | + 'dispatched_tasks' => 0, |
| 216 | + 'existing_task_failures' => [], |
| 217 | + 'missing_run_failures' => [], |
| 218 | + 'deadline_expired_candidates' => 0, |
| 219 | + 'deadline_expired_tasks_created' => 0, |
| 220 | + 'deadline_expired_failures' => [], |
| 221 | + 'activity_timeout_candidates' => 0, |
| 222 | + 'activity_timeouts_enforced' => 0, |
| 223 | + 'activity_timeout_failures' => [], |
| 224 | + ]; |
| 225 | + } |
| 226 | + }; |
| 227 | + |
| 228 | + $this->app->instance(MatchingRole::class, $fake); |
| 229 | + |
| 230 | + $expected = [ |
| 231 | + 'connection' => 'redis', |
| 232 | + 'queue' => 'critical', |
| 233 | + 'run_ids' => ['run-a', 'run-b'], |
| 234 | + 'instance_id' => 'instance-42', |
| 235 | + 'respect_throttle' => true, |
| 236 | + 'throttled' => false, |
| 237 | + 'selected_existing_task_candidates' => 0, |
| 238 | + 'selected_missing_task_candidates' => 0, |
| 239 | + 'selected_total_candidates' => 0, |
| 240 | + 'repaired_existing_tasks' => 0, |
| 241 | + 'repaired_missing_tasks' => 0, |
| 242 | + 'dispatched_tasks' => 0, |
| 243 | + 'existing_task_failures' => [], |
| 244 | + 'missing_run_failures' => [], |
| 245 | + 'deadline_expired_candidates' => 0, |
| 246 | + 'deadline_expired_tasks_created' => 0, |
| 247 | + 'deadline_expired_failures' => [], |
| 248 | + 'activity_timeout_candidates' => 0, |
| 249 | + 'activity_timeouts_enforced' => 0, |
| 250 | + 'activity_timeout_failures' => [], |
| 251 | + ]; |
| 252 | + |
| 253 | + $this->artisan('workflow:v2:repair-pass', [ |
| 254 | + '--connection' => 'redis', |
| 255 | + '--queue' => 'critical', |
| 256 | + '--run-id' => ['run-a', 'run-b'], |
| 257 | + '--instance-id' => 'instance-42', |
| 258 | + '--respect-throttle' => true, |
| 259 | + '--json' => true, |
| 260 | + ]) |
| 261 | + ->expectsOutput(json_encode($expected, JSON_UNESCAPED_SLASHES)) |
| 262 | + ->assertSuccessful(); |
| 263 | + |
| 264 | + $this->assertSame([ |
| 265 | + 'connection' => 'redis', |
| 266 | + 'queue' => 'critical', |
| 267 | + 'respectThrottle' => true, |
| 268 | + 'runIds' => ['run-a', 'run-b'], |
| 269 | + 'instanceId' => 'instance-42', |
| 270 | + ], $fake->lastRunPassArguments); |
| 271 | + } |
| 272 | + |
175 | 273 | public function testRunIdScopeRepairsOnlyTheSelectedMissingTaskRun(): void |
176 | 274 | { |
177 | 275 | Queue::fake(); |
|
0 commit comments