Skip to content

Commit

Permalink
Test QueueHealth command
Browse files Browse the repository at this point in the history
  • Loading branch information
NFarrington committed Mar 26, 2019
1 parent fc6ea51 commit 2b40533
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Console/Commands/QueueHealth.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function handle()
return 1;
}

echo "The queue has $queueSize items, and is processing.";
$this->line("The queue has $queueSize items, and is processing.");

return 0;
}
Expand Down
43 changes: 43 additions & 0 deletions tests/Feature/QueueHealthTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Tests\Feature;

use Illuminate\Support\Facades\Cache;
use Tests\TestCase;

class QueueHealthTest extends TestCase
{
/** @test */
function queue_is_healthy_when_empty()
{
$mock = $this->createMock(\Illuminate\Contracts\Queue\Queue::class);
$mock->method('size')->willReturn(0);
$this->app->instance(\Illuminate\Contracts\Queue\Queue::class, $mock);

$this->artisan('queue:health')->assertExitCode(0);
}

/** @test */
function queue_is_healthy_when_a_job_was_recently_processed()
{
Cache::forever('queue.job.last-processed', \Carbon\Carbon::now());

$mock = $this->createMock(\Illuminate\Contracts\Queue\Queue::class);
$mock->method('size')->willReturn(1);
$this->app->instance(\Illuminate\Contracts\Queue\Queue::class, $mock);

$this->artisan('queue:health')->assertExitCode(0);
}

/** @test */
function queue_is_unhealthy_when_a_job_was_not_recently_processed()
{
Cache::forever('queue.job.last-processed', \Carbon\Carbon::now()->subHour());

$mock = $this->createMock(\Illuminate\Contracts\Queue\Queue::class);
$mock->method('size')->willReturn(1);
$this->app->instance(\Illuminate\Contracts\Queue\Queue::class, $mock);

$this->artisan('queue:health')->assertExitCode(1);
}
}

0 comments on commit 2b40533

Please sign in to comment.