Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run queue tests with Laravel 8 #502

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions features/fixtures/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ services:
published: 61266

laravel8:
init: true
build:
context: laravel8
args:
Expand Down
9 changes: 2 additions & 7 deletions features/fixtures/laravel8/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
DB_CONNECTION=sqlite

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
QUEUE_CONNECTION=database
SESSION_DRIVER=file
SESSION_LIFETIME=120

Expand Down
3 changes: 3 additions & 0 deletions features/fixtures/laravel8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ RUN cp .env.example .env
RUN composer install
RUN php artisan key:generate

# create database & apply migrations
RUN touch database/database.sqlite && php artisan migrate --no-interaction

CMD php -S 0.0.0.0:8000 -t public
27 changes: 27 additions & 0 deletions features/fixtures/laravel8/app/Jobs/HandledJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Jobs;

use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class HandledJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Bugsnag::notifyException(new Exception('Handled :)'));
}
}
33 changes: 33 additions & 0 deletions features/fixtures/laravel8/app/Jobs/UnhandledJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use RuntimeException;

class UnhandledJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public int $tries;

public function __construct(int $tries)
{
$this->tries = $tries;
}

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
throw new RuntimeException('uh oh :o');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('jobs');
}
}
9 changes: 9 additions & 0 deletions features/fixtures/laravel8/routes/web.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
Expand Down Expand Up @@ -52,6 +53,14 @@
Route::view('/handled_view_exception', 'handledexception');
Route::view('/handled_view_error', 'handlederror');

Route::get('/queue/unhandled', function (Request $request) {
\App\Jobs\UnhandledJob::dispatch((int) $request->query('tries', '1'));
});

Route::get('/queue/handled', function (Request $request) {
\App\Jobs\HandledJob::dispatch((int) $request->query('tries', '1'));
});

/**
* Return some diagnostics if an OOM did not happen when it should have.
*
Expand Down
6 changes: 3 additions & 3 deletions features/queues.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: Queue support

@not-laravel-latest @not-laravel51 @not-laravel56 @not-laravel58 @not-laravel66 @not-laravel8 @not-lumen8
@not-laravel-latest @not-laravel51 @not-laravel56 @not-laravel58 @not-laravel66 @not-lumen8
Scenario: Unhandled exceptions are delivered from queues
Given I start the laravel fixture
And I start the laravel queue worker
Expand All @@ -21,7 +21,7 @@ Scenario: Unhandled exceptions are delivered from queues
And the event "severityReason.type" equals "unhandledExceptionMiddleware"
And the event "severityReason.attributes.framework" equals "Laravel"

@not-laravel-latest @not-laravel51 @not-laravel56 @not-laravel58 @not-laravel66 @not-laravel8 @not-lumen8
@not-laravel-latest @not-laravel51 @not-laravel56 @not-laravel58 @not-laravel66 @not-lumen8
Scenario: Unhandled exceptions are delivered from queued jobs with multiple attmpts
Given I start the laravel fixture
And I start the laravel queue worker
Expand Down Expand Up @@ -78,7 +78,7 @@ Scenario: Unhandled exceptions are delivered from queued jobs with multiple attm
And the event "severityReason.type" equals "unhandledExceptionMiddleware"
And the event "severityReason.attributes.framework" equals "Laravel"

@not-laravel-latest @not-laravel51 @not-laravel56 @not-laravel58 @not-laravel66 @not-laravel8 @not-lumen8
@not-laravel-latest @not-laravel51 @not-laravel56 @not-laravel58 @not-laravel66 @not-lumen8
Scenario: Handled exceptions are delivered from queues
Given I start the laravel fixture
And I start the laravel queue worker
Expand Down