1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
<?php
namespace Illuminate\Tests\Integration\Database\Queue;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\DB;
use Illuminate\Tests\Integration\Database\DatabaseTestCase;
use Orchestra\Testbench\Attributes\WithConfig;
use Orchestra\Testbench\Attributes\WithMigration;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Symfony\Component\Process\Exception\ProcessSignaledException;
use Throwable;
use function Orchestra\Testbench\remote;
#[RequiresPhpExtension('pcntl')]
#[WithMigration('laravel', 'queue')]
#[WithConfig('queue.default', 'database')]
class QueueTransactionTest extends DatabaseTestCase
{
use DatabaseMigrations;
protected function setUp(): void
{
parent::setUp();
if ($this->usesSqliteInMemoryDatabaseConnection()) {
$this->markTestSkipped('Test does not support using :memory: database connection');
}
}
#[DataProvider('timeoutJobs')]
public function testItCanHandleTimeoutJob($job)
{
dispatch($job);
$this->assertSame(1, DB::table('jobs')->count());
$this->assertSame(0, DB::table('failed_jobs')->count());
try {
remote('queue:work --stop-when-empty', [
'DB_CONNECTION' => config('database.default'),
'QUEUE_CONNECTION' => config('queue.default'),
])->run();
} catch (Throwable $e) {
$this->assertInstanceOf(ProcessSignaledException::class, $e);
$this->assertSame('The process has been signaled with signal "9".', $e->getMessage());
}
$this->assertSame(0, DB::table('jobs')->count());
$this->assertSame(1, DB::table('failed_jobs')->count());
}
public static function timeoutJobs(): array
{
return [
[new Fixtures\TimeOutJobWithTransaction()],
[new Fixtures\TimeOutJobWithNestedTransactions()],
[new Fixtures\TimeOutNonBatchableJobWithTransaction()],
[new Fixtures\TimeOutNonBatchableJobWithNestedTransactions()],
];
}
}
|