Skip to content

Commit

Permalink
Add test for released jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
paras-malhotra committed Nov 3, 2020
1 parent 3a8baae commit e2067d3
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions tests/Integration/Queue/UniqueJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ public function testLockIsNotReleasedForJobRetries()
$this->assertTrue($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
}

public function testLockIsNotReleasedForJobReleases()
{
UniqueTestReleasedJob::$handled = false;
dispatch($job = new UniqueTestReleasedJob);

$this->assertFalse($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());

$this->artisan('queue:work', [
'connection' => 'database',
'--once' => true,
]);

$this->assertTrue($job::$handled);
$this->assertFalse($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());

UniqueTestReleasedJob::$handled = false;
$this->artisan('queue:work', [
'connection' => 'database',
'--once' => true,
]);

$this->assertFalse($job::$handled);
$this->assertTrue($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
}

protected function getLockKey($job)
{
return 'unique:'.(is_string($job) ? $job : get_class($job));
Expand All @@ -135,10 +160,10 @@ public function handle()

class UniqueTestFailJob implements ShouldQueue, UniqueJob
{
public $tries = 1;

use InteractsWithQueue, Queueable, Dispatchable;

public $tries = 1;

public static $handled = false;

public function handle()
Expand All @@ -149,6 +174,20 @@ public function handle()
}
}

class UniqueTestReleasedJob extends UniqueTestFailJob
{
public $tries = 1;

public $connection = 'database';

public function handle()
{
static::$handled = true;

$this->release();
}
}

class UniqueTestRetryJob extends UniqueTestFailJob
{
public $tries = 2;
Expand Down

0 comments on commit e2067d3

Please sign in to comment.