8000 bug #42194 [RateLimiter] fix: sliding window policy to use microtime … · symfony/symfony@e616963 · GitHub
[go: up one dir, main page]

Skip to content

Commit e616963

Browse files
committed
bug #42194 [RateLimiter] fix: sliding window policy to use microtime - fix test
1 parent c758e22 commit e616963

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Symfony/Component/RateLimiter/Tests/RateLimitTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public function testEnsureAcceptedThrowsRateLimitExceptionIfNotAccepted()
4848
public function testWaitUsesMicrotime()
4949
{
5050
ClockMock::register(RateLimit::class);
51-
$rateLimit = new RateLimit(10, new \DateTimeImmutable('+2500 ms'), true, 10);
51+
$retryAfter = time() + 2.5; // get timestamp in the middle of a second (xxx.5)
52+
$rateLimit = new RateLimit(10, \DateTimeImmutable::createFromFormat('U.u', $retryAfter), true, 10);
5253

53-
$start = microtime(true);
54-
$rateLimit->wait(); // wait 2.5 seconds
55-
$this->assertEqualsWithDelta($start + 2.5, microtime(true), 0.1);
54+
$rateLimit->wait(); // wait until $retryAfter (~2.5 seconds)
55+
$this->assertEqualsWithDelta($retryAfter, microtime(true), 0.49);
5656
}
5757
}

0 commit comments

Comments
 (0)
0