Skip to content

Commit 0a0c1de

Browse files
authored
Use the Sleep::fake feature instead of microtime (#48166)
1 parent 6ce1c75 commit 0a0c1de

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tests/Http/HttpClientTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Illuminate\Support\Carbon;
2424
use Illuminate\Support\Collection;
2525
use Illuminate\Support\Fluent;
26+
use Illuminate\Support\Sleep;
2627
use Illuminate\Support\Str;
2728
use JsonSerializable;
2829
use Mockery as m;
@@ -1715,7 +1716,7 @@ public function testExceptionThrownInRetryCallbackWithoutRetrying()
17151716

17161717
public function testRequestsWillBeWaitingSleepMillisecondsReceivedBeforeRetry()
17171718
{
1718-
$startTime = microtime(true);
1719+
Sleep::fake();
17191720

17201721
$this->factory->fake([
17211722
'*' => $this->factory->sequence()
@@ -1734,8 +1735,13 @@ public function testRequestsWillBeWaitingSleepMillisecondsReceivedBeforeRetry()
17341735

17351736
$this->factory->assertSentCount(3);
17361737

1737-
// Make sure was waited 300ms for the first two attempts
1738-
$this->assertEqualsWithDelta(0.3, microtime(true) - $startTime, 0.03);
1738+
// Make sure we waited 300ms for the first two attempts
1739+
Sleep::assertSleptTimes(2);
1740+
1741+
Sleep::assertSequence([
1742+
Sleep::usleep(100_000),
1743+
Sleep::usleep(200_000),
1744+
]);
17391745
}
17401746

17411747
public function testMiddlewareRunsWhenFaked()

0 commit comments

Comments
 (0)