@@ -59,19 +59,21 @@ public function testWorkerCanWorkUntilQueueIsEmpty()
59
59
$ secondJob = new WorkerFakeJob ,
60
60
]]);
61
61
62
- $ this ->expectException (LoopBreakerException::class);
62
+ try {
63
+ $ worker ->daemon ('default ' , 'queue ' , $ workerOptions );
63
64
64
- $ worker ->daemon ('default ' , 'queue ' , $ workerOptions );
65
+ $ this ->fail ('Expected LoopBreakerException to be thrown. ' );
66
+ } catch (LoopBreakerException $ e ) {
67
+ $ this ->assertTrue ($ firstJob ->fired );
65
68
66
- $ this ->assertTrue ($ firstJob ->fired );
69
+ $ this ->assertTrue ($ secondJob ->fired );
67
70
68
- $ this ->assertTrue ( $ secondJob -> fired );
71
+ $ this ->assertSame ( 0 , $ worker -> stoppedWithStatus );
69
72
70
- $ this ->assertSame ( 0 , $ worker -> stoppedWithStatus );
73
+ $ this ->events -> shouldHaveReceived ( ' dispatch ' )-> with (m:: type (JobProcessing::class))-> twice ( );
71
74
72
- $ this ->events ->shouldHaveReceived ('dispatch ' )->with (m::type (JobProcessing::class))->twice ();
73
-
74
- $ this ->events ->shouldHaveReceived ('dispatch ' )->with (m::type (JobProcessed::class))->twice ();
75
+ $ this ->events ->shouldHaveReceived ('dispatch ' )->with (m::type (JobProcessed::class))->twice ();
76
+ }
75
77
}
76
78
77
79
public function testJobCanBeFiredBasedOnPriority ()
@@ -276,21 +278,23 @@ public function testJobRunsIfAppIsNotInMaintenanceMode()
276
278
277
279
$ maintenanceModeChecker = function () {
278
280
if ($ this ->maintenanceFlags ) {
279
- return array_pop ($ this ->maintenanceFlags );
281
+ return array_shift ($ this ->maintenanceFlags );
280
282
}
281
283
282
284
throw new LoopBreakerException ;
283
285
};
284
286
285
- $ this ->expectException (LoopBreakerException::class);
286
-
287
287
$ worker = $ this ->getWorker ('default ' , ['queue ' => [$ firstJob , $ secondJob ]], $ maintenanceModeChecker );
288
288
289
- $ worker ->daemon ('default ' , 'queue ' , $ this ->workerOptions ());
289
+ try {
290
+ $ worker ->daemon ('default ' , 'queue ' , $ this ->workerOptions ());
290
291
291
- $ this ->assertEquals ($ firstJob ->attempts , 1 );
292
+ $ this ->fail ('Expected LoopBreakerException to be thrown ' );
293
+ } catch (LoopBreakerException $ e ) {
294
+ $ this ->assertSame (1 , $ firstJob ->attempts );
292
295
293
- $ this ->assertEquals ($ firstJob ->attempts , 0 );
296
+ $ this ->assertSame (0 , $ secondJob ->attempts );
297
+ }
294
298
}
295
299
296
300
public function testJobDoesNotFireIfDeleted ()
@@ -349,6 +353,7 @@ private function workerOptions(array $overrides = [])
349
353
class InsomniacWorker extends Worker
350
354
{
351
355
public $ sleptFor ;
356
+ public $ stopOnMemoryExceeded = false ;
352
357
353
358
public function sleep ($ seconds )
354
359
{
@@ -366,6 +371,11 @@ public function daemonShouldRun(WorkerOptions $options, $connectionName, $queue)
366
371
{
367
372
return ! ($ this ->isDownForMaintenance )();
368
373
}
374
+
375
+ public function memoryExceeded ($ memoryLimit )
376
+ {
377
+ return $ this ->stopOnMemoryExceeded ;
378
+ }
369
379
}
370
380
371
381
class WorkerFakeManager extends QueueManager
0 commit comments