|
12 | 12 | use Illuminate\Support\Facades\Config;
|
13 | 13 | use Illuminate\Support\Facades\Event;
|
14 | 14 | use Illuminate\Support\Facades\Mail;
|
| 15 | +use Illuminate\Support\Facades\Redis; |
15 | 16 | use Illuminate\Support\Str;
|
16 | 17 |
|
17 | 18 | use function Pest\Laravel\travelTo;
|
|
30 | 31 |
|
31 | 32 | setTraceId('0d3ca349-e222-4982-ac23-2343692de258');
|
32 | 33 | Config::set('queue.default', 'database');
|
| 34 | + Redis::command('FLUSHALL'); |
33 | 35 | })->skip(version_compare(Application::VERSION, '11.0.0', '<'), 'Laravel 10 support is pending');
|
34 | 36 |
|
35 |
| -it('ingests processed job attempts', function () { |
| 37 | +$workCommands = [ |
| 38 | + 'queue:work', |
| 39 | + 'horizon:work', |
| 40 | +]; |
| 41 | + |
| 42 | +$workOptions = [ |
| 43 | + '--max-jobs' => 1, |
| 44 | + '--sleep' => 0, |
| 45 | + '--stop-when-empty' => true, |
| 46 | + '--tries' => 1, |
| 47 | +]; |
| 48 | + |
| 49 | +it('ingests processed job attempts', function ($workCommand) use ($workOptions) { |
36 | 50 | $ingest = fakeIngest();
|
37 | 51 | Str::createUuidsUsingSequence([
|
38 | 52 | $jobId = 'e2cb5fa7-6c2e-4bc5-82c9-45e79c3e8fdd',
|
39 | 53 | $attemptId = '02cb9091-8973-427f-8d3f-042f2ec4e862',
|
40 | 54 | ]);
|
41 | 55 | ProcessedJob::dispatch();
|
42 | 56 |
|
43 |
| - Artisan::call('queue:work', ['--max-jobs' => 1, '--stop-when-empty' => true, '--sleep' => 0]); |
| 57 | + Artisan::call($workCommand, $workOptions); |
44 | 58 |
|
45 | 59 | $ingest->assertWrittenTimes(1);
|
46 | 60 | $ingest->assertLatestWrite('job-attempt:*', [
|
|
76 | 90 | 'peak_memory_usage' => 1234,
|
77 | 91 | ],
|
78 | 92 | ]);
|
79 |
| -}); |
| 93 | +})->with($workCommands); |
80 | 94 |
|
81 |
| -it('ingests job released job attempts', function () { |
| 95 | +it('ingests job released job attempts', function ($workCommand) use ($workOptions) { |
82 | 96 | $ingest = fakeIngest();
|
83 | 97 | Str::createUuidsUsingSequence([
|
84 | 98 | $jobId = 'e2cb5fa7-6c2e-4bc5-82c9-45e79c3e8fdd',
|
85 | 99 | $attemptId = '02cb9091-8973-427f-8d3f-042f2ec4e862',
|
86 | 100 | ]);
|
87 | 101 | ReleasedJob::dispatch();
|
88 | 102 |
|
89 |
| - Artisan::call('queue:work', ['--max-jobs' => 1, '--stop-when-empty' => true, '--sleep' => 0]); |
| 103 | + Artisan::call($workCommand, $workOptions); |
90 | 104 |
|
91 | 105 | $ingest->assertWrittenTimes(1);
|
92 | 106 | $ingest->assertLatestWrite('job-attempt:*', [
|
|
122 | 136 | 'peak_memory_usage' => 1234,
|
123 | 137 | ],
|
124 | 138 | ]);
|
125 |
| -}); |
| 139 | +})->with($workCommands); |
126 | 140 |
|
127 |
| -it('ingests job failed job attempts', function () { |
| 141 | +it('ingests job failed job attempts', function ($workCommand) use ($workOptions) { |
128 | 142 | $ingest = fakeIngest();
|
129 | 143 | Str::createUuidsUsingSequence([
|
130 | 144 | $jobId = 'e2cb5fa7-6c2e-4bc5-82c9-45e79c3e8fdd',
|
131 | 145 | $attemptId = '02cb9091-8973-427f-8d3f-042f2ec4e862',
|
132 | 146 | ]);
|
133 | 147 | FailedJob::dispatch();
|
134 | 148 |
|
135 |
| - Artisan::call('queue:work', ['--max-jobs' => 1, '--stop-when-empty' => true, '--sleep' => 0]); |
| 149 | + Artisan::call($workCommand, $workOptions); |
136 | 150 |
|
137 | 151 | $ingest->assertWrittenTimes(1);
|
138 | 152 | $ingest->assertLatestWrite('job-attempt:*', [
|
|
170 | 184 | ]);
|
171 | 185 | $ingest->assertLatestWrite('exception:0.execution_source', 'job');
|
172 | 186 | $ingest->assertLatestWrite('exception:0.execution_id', $attemptId);
|
173 |
| -}); |
| 187 | +})->with($workCommands); |
174 | 188 |
|
175 | 189 | it('does not ingest jobs dispatched on the sync queue', function () {
|
176 | 190 | $ingest = fakeIngest();
|
|
179 | 193 | $ingest->assertWrittenTimes(0);
|
180 | 194 | });
|
181 | 195 |
|
182 |
| -it('captures closure job', function () { |
| 196 | +it('captures closure job', function ($workCommand) use ($workOptions) { |
183 | 197 | $ingest = fakeIngest();
|
184 | 198 | Str::createUuidsUsingSequence([
|
185 | 199 | $jobId = 'e2cb5fa7-6c2e-4bc5-82c9-45e79c3e8fdd',
|
|
190 | 204 | travelTo(now()->addMicroseconds(2500));
|
191 | 205 | });
|
192 | 206 |
|
193 |
| - Artisan::call('queue:work', ['--max-jobs' => 1, '--stop-when-empty' => true, '--sleep' => 0]); |
| 207 | + Artisan::call($workCommand, $workOptions); |
194 | 208 |
|
195 | 209 | $ingest->assertWrittenTimes(1);
|
196 | 210 | $ingest->assertLatestWrite('job-attempt:*', [
|
|
226 | 240 | 'peak_memory_usage' => 1234,
|
227 | 241 | ],
|
228 | 242 | ]);
|
229 |
| -}); |
| 243 | +})->with($workCommands); |
230 | 244 |
|
231 |
| -it('captures queued event listener', function () { |
| 245 | +it('captures queued event listener', function ($workCommand) use ($workOptions) { |
232 | 246 | $ingest = fakeIngest();
|
233 | 247 | Str::createUuidsUsingSequence([
|
234 | 248 | $jobId = 'e2cb5fa7-6c2e-4bc5-82c9-45e79c3e8fdd',
|
|
237 | 251 | Event::listen(MyEvent::class, MyEventListener::class);
|
238 | 252 | Event::dispatch(new MyEvent);
|
239 | 253 |
|
240 |
| - Artisan::call('queue:work', ['--max-jobs' => 1, '--stop-when-empty' => true, '--sleep' => 0]); |
| 254 | + Artisan::call($workCommand, $workOptions); |
241 | 255 |
|
242 | 256 | $ingest->assertWrittenTimes(1);
|
243 | 257 | $ingest->assertLatestWrite('job-attempt:*', [
|
|
273 | 287 | 'peak_memory_usage' => 1234,
|
274 | 288 | ],
|
275 | 289 | ]);
|
276 |
| -}); |
| 290 | +})->with($workCommands); |
277 | 291 |
|
278 |
| -it('captures queued mail', function () { |
| 292 | +it('captures queued mail', function ($workCommand) use ($workOptions) { |
279 | 293 | $ingest = fakeIngest();
|
280 | 294 | Str::createUuidsUsingSequence([
|
281 | 295 | $jobId = 'e2cb5fa7-6c2e-4bc5-82c9-45e79c3e8fdd',
|
|
285 | 299 |
|
286 | 300 | Mail:: to( '[email protected]')-> queue( new MyQueuedMail);
|
287 | 301 |
|
288 |
| - Artisan::call('queue:work', ['--max-jobs' => 1, '--stop-when-empty' => true, '--sleep' => 0]); |
| 302 | + Artisan::call($workCommand, $workOptions); |
289 | 303 |
|
290 | 304 | $ingest->assertWrittenTimes(1);
|
291 | 305 | $ingest->assertLatestWrite('job-attempt:*', [
|
|
345 | 359 | 'failed' => false,
|
346 | 360 | ],
|
347 | 361 | ]);
|
348 |
| -}); |
| 362 | +})->with($workCommands); |
349 | 363 |
|
350 |
| -it('captures multiple job attempts', function () { |
| 364 | +it('captures multiple job attempts', function ($workCommand) use ($workOptions) { |
351 | 365 | $ingest = fakeIngest();
|
352 | 366 | FailedJob::dispatch();
|
353 | 367 |
|
354 |
| - Artisan::call('queue:work', ['--max-jobs' => 2, '--tries' => 2, '--stop-when-empty' => true, '--sleep' => 0]); |
| 368 | + Artisan::call($workCommand, [...$workOptions, '--max-jobs' => 2, '--tries' => 2]); |
355 | 369 |
|
356 | 370 | $ingest->assertWrittenTimes(2);
|
357 | 371 | $ingest->assertLatestWrite('job-attempt:0.attempt', 2);
|
358 |
| -}); |
| 372 | +})->with($workCommands); |
359 | 373 |
|
360 | 374 | final class ProcessedJob implements ShouldQueue
|
361 | 375 | {
|
|
0 commit comments