File tree 4 files changed +15
-26
lines changed
4 files changed +15
-26
lines changed Original file line number Diff line number Diff line change 2
2
.idea /
3
3
.phpunit.result.cache
4
4
.phpunit.cache
5
- .env
5
+ .env
6
+ /coverage
Original file line number Diff line number Diff line change 16
16
<env name =" QUEUE_DRIVER" value =" cloudtasks" />
17
17
<env name =" DB_DRIVER" value =" mysql" />
18
18
</php >
19
+ <source >
20
+ <include >
21
+ <directory suffix =" .php" >./src</directory >
22
+ </include >
23
+ </source >
19
24
</phpunit >
Original file line number Diff line number Diff line change 4
4
5
5
namespace Tests \Support ;
6
6
7
+ use Error ;
7
8
use Illuminate \Support \Facades \Event ;
8
9
use Illuminate \Queue \Events \WorkerStopping ;
10
+ use Symfony \Component \ErrorHandler \Error \FatalError ;
9
11
10
12
class SimpleJobWithTimeout extends SimpleJob
11
13
{
12
14
public $ timeout = 3 ;
13
15
14
16
public function handle ()
15
17
{
16
- Event::listen (WorkerStopping::class, function () {
17
- event (new JobOutput ('SimpleJobWithTimeout:worker-stopping ' ));
18
- });
19
-
20
- event (new JobOutput ('SimpleJobWithTimeout:1 ' ));
21
- sleep (1 );
22
- event (new JobOutput ('SimpleJobWithTimeout:2 ' ));
23
- sleep (1 );
24
- event (new JobOutput ('SimpleJobWithTimeout:3 ' ));
25
- sleep (1 );
26
- event (new JobOutput ('SimpleJobWithTimeout:4 ' ));
27
- sleep (1 );
28
- event (new JobOutput ('SimpleJobWithTimeout:5 ' ));
18
+ throw new FatalError ('Maximum execution time of 30 seconds exceeded ' , 500 , [
19
+ 'file ' => __FILE__ ,
20
+ 'line ' => __LINE__ ,
21
+ ]);
29
22
}
30
23
}
Original file line number Diff line number Diff line change @@ -289,23 +289,13 @@ public function retried_jobs_get_a_new_name()
289
289
#[Test]
290
290
public function test_job_timeout ()
291
291
{
292
- $ this ->markTestSkipped ('Currently seemingly impossible to test job timeouts. ' );
293
-
294
292
// Arrange
295
- Event::fake (JobOutput ::class);
293
+ Event::fake (JobReleasedAfterException ::class);
296
294
297
295
// Act
298
296
$ this ->dispatch (new SimpleJobWithTimeout )->run ();
299
297
300
298
// Assert
301
- $ events = Event::dispatched (JobOutput::class)->map (fn ($ event ) => $ event [0 ]->output )->toArray ();
302
- $ this ->assertEquals ([
303
- 'SimpleJobWithTimeout:1 ' ,
304
- 'SimpleJobWithTimeout:2 ' ,
305
- 'SimpleJobWithTimeout:3 ' ,
306
- 'SimpleJobWithTimeout:worker-stopping ' ,
307
- 'SimpleJobWithTimeout:4 ' ,
308
- 'SimpleJobWithTimeout:5 ' ,
309
- ], $ events );
299
+ Event::assertDispatched (JobReleasedAfterException::class);
310
300
}
311
301
}
You can’t perform that action at this time.
0 commit comments