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

Fix timing sensitive flaky test #48663

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 7 additions & 8 deletions tests/Integration/Queue/ThrottlesExceptionsWithRedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Queue\CallQueuedHandler;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\Middleware\ThrottlesExceptionsWithRedis;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Mockery as m;
use Orchestra\Testbench\TestCase;
Expand All @@ -23,6 +24,8 @@ protected function setUp(): void
parent::setUp();

$this->setUpRedis();

Carbon::setTestNow(now());
}

protected function tearDown(): void
Expand All @@ -31,17 +34,16 @@ protected function tearDown(): void

$this->tearDownRedis();

Carbon::setTestNow();

m::close();
}

public function testCircuitIsOpenedForJobErrors()
{
$this->assertJobWasReleasedImmediately(CircuitBreakerWithRedisTestJob::class, $key = Str::random());
$this->assertJobWasReleasedImmediately(CircuitBreakerWithRedisTestJob::class, $key);

retry(2, function () use ($key) {
$this->assertJobWasReleasedWithDelay(CircuitBreakerWithRedisTestJob::class, $key);
});
$this->assertJobWasReleasedWithDelay(CircuitBreakerWithRedisTestJob::class, $key);
}

public function testCircuitStaysClosedForSuccessfulJobs()
Expand All @@ -57,10 +59,7 @@ public function testCircuitResetsAfterSuccess()
$this->assertJobRanSuccessfully(CircuitBreakerWithRedisSuccessfulJob::class, $key);
$this->assertJobWasReleasedImmediately(CircuitBreakerWithRedisTestJob::class, $key);
$this->assertJobWasReleasedImmediately(CircuitBreakerWithRedisTestJob::class, $key);

retry(2, function () use ($key) {
$this->assertJobWasReleasedWithDelay(CircuitBreakerWithRedisTestJob::class, $key);
});
$this->assertJobWasReleasedWithDelay(CircuitBreakerWithRedisTestJob::class, $key);
}

protected function assertJobWasReleasedImmediately($class, $key)
Expand Down