Skip to content

Commit

Permalink
Merge pull request #506 from bugsnag/laravel56-queue-tests
Browse files Browse the repository at this point in the history
Run queue tests with Laravel 5.6
  • Loading branch information
imjoehaines authored Dec 6, 2022
2 parents 2d3b73b + 0c0b190 commit f40c02d
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 10 deletions.
9 changes: 2 additions & 7 deletions features/fixtures/laravel56/.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
DB_CONNECTION=sqlite

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync
QUEUE_DRIVER=database

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
Expand Down
3 changes: 3 additions & 0 deletions features/fixtures/laravel56/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ COPY --from=composer:2.2 /usr/bin/composer /usr/local/bin/composer
RUN composer install
RUN php artisan key:generate

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

CMD php artisan serve --port=8000 --host=0.0.0.0
26 changes: 26 additions & 0 deletions features/fixtures/laravel56/app/Jobs/HandledJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Jobs;

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

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

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

namespace App\Jobs;

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

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\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

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');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

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

class CreateFailedJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('failed_jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('failed_jobs');
}
}
9 changes: 9 additions & 0 deletions features/fixtures/laravel56/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
|
*/

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

Route::get('/', function () {
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();
});

/**
* 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-lumen8
@not-laravel-latest @not-laravel51 @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-lumen8
@not-laravel-latest @not-laravel51 @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-lumen8
@not-laravel-latest @not-laravel51 @not-lumen8
Scenario: Handled exceptions are delivered from queues
Given I start the laravel fixture
And I start the laravel queue worker
Expand Down

0 comments on commit f40c02d

Please sign in to comment.