8000 Add failWhen method to ThrottlesExceptions job middleware by michaeldzjap · Pull Request #56180 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

Add failWhen method to ThrottlesExceptions job middleware #56180

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

Merged
merged 3 commits into from
Jul 1, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: add test for failWhen method
  • Loading branch information
michaeldzjap committed Jun 30, 2025
commit b0d8ca14ae8cb0ff1eadc0dccd66dd9205a01834
45 changes: 45 additions & 0 deletions tests/Integration/Queue/ThrottlesExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public function testCircuitCanSkipJob()
$this->assertJobWasDeleted(CircuitBreakerSkipJob::class);
}

public function testCircuitCanFailJob()
{
$this->assertJobWasFailed(CircuitBreakerFailedJob::class);
}

protected function assertJobWasReleasedImmediately($class)
{
$class::$handled = false;
Expand Down Expand Up @@ -108,6 +113,27 @@ protected function assertJobWasDeleted($class)
$this->assertTrue($class::$handled);
}

protected function assertJobWasFailed($class)
{
$class::$handled = false;
$instance = new CallQueuedHandler(new Dispatcher($this->app), $this->app);

$job = m::mock(Job::class);

$job->shouldReceive('hasFailed')->once()->andReturn(true);
$job->shouldReceive('fail')->once();
$job->shouldReceive('isDeleted')->andReturn(true);
$job->shouldReceive('isReleased')->twice()->andReturn(false);
$job->shouldReceive('isDeletedOrReleased')->once()->andReturn(true);
$job->shouldReceive('uuid')->andReturn('simple-test-uuid');

$instance->call($job, [
'command' => serialize($command = new $class),
]);

$this->assertTrue($class::$handled);
}

protected function assertJobRanSuccessfully($class)
{
$class::$handled = false;
Expand Down Expand Up @@ -359,6 +385,25 @@ public function middleware()
}
}

class CircuitBreakerFailedJob
{
use InteractsWithQueue, Queueable;

public static $handled = false;

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

throw new Exception;
}

public function middleware()
{
return [(new ThrottlesExceptions(2, 10 * 60))->failWhen(Exception::class)];
}
}

class CircuitBreakerSuccessfulJob
{
use InteractsWithQueue, Queueable;
Expand Down
Loading
0