Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1c79d80

Browse files
committed
minor#43688 [RateLimiter] bug#42194 fix: sliding window policy to use microtime - fix test (jlekowski)
This PR was merged into the 5.4 branch.Discussion----------[RateLimiter] bug#42194 fix: sliding window policy to use microtime - fix test| Q | A| ------------- | ---| Branch? | 5.4| Bug fix? | yes| New feature? | no <!-- please update src/**/CHANGELOG.md files -->| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tickets |Fix#42194 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->| License | MIT| Doc PR | symfony/symfony-docs#... <!-- required for new features -->As pointed out in the comment#43677 (comment), `RateLimitTest::testWaitUsesMicrotime()` fails intermittently.I have looked at all `PHPUnit` actions since the test was introduced and interestingly, the fails only occurred during `7.2` test, and the time difference was always ~1.3s.Commits-------e616963 bug#42194 [RateLimiter] fix: sliding window policy to use microtime - fix test
2 parents1580757 +e616963 commit1c79d80

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
publicfunctiontestWaitUsesMicrotime()
4949
{
5050
ClockMock::register(RateLimit::class);
51-
$rateLimit =newRateLimit(10,new \DateTimeImmutable('+2500 ms'),true,10);
51+
$retryAfter =time() +2.5;// get timestamp in the middle of a second (xxx.5)
52+
$rateLimit =newRateLimit(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)

[8]ページ先頭

©2009-2025 Movatter.jp