Skip to content

Commit

Permalink
Fix timing sensitive flaky test (laravel#48664)
Browse files Browse the repository at this point in the history
  • Loading branch information
KentarouTakeda authored and timacdonald committed Oct 24, 2023
1 parent 598b10f commit 1532c1d
Showing 1 changed file with 7 additions and 8 deletions.
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

0 comments on commit 1532c1d

Please sign in to comment.