-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[RateLimiter] bug #42194 fix: sliding window policy to use microtime #43677
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
Conversation
@@ -72,4 +72,34 @@ public function testLongIntervalCreate() | |||
$new = SlidingWindow::createFromPreviousWindow($window, 60); | |||
$this->assertFalse($new->isExpired()); | |||
} | |||
|
|||
public function testCreateFromPreviousWindowUsesMicrotime() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests consistently pass after the changes. The old code would inconsistently fail, though (depend on the microtome(true)
result at the moment of running the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
Thank you @jlekowski. |
This PR introduced a randomly failing test https://github.com/symfony/symfony/runs/3990643552?check_suite_focus=true#step:8:987. @jlekowski could you please have a look? |
@chalasr, I'll have a look at it. Thanks for letting me know. |
…se 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
Other parts of
RateLimiter
usemicrotime()
, while sliding window policy usestime()
instead. That means the window may expire only up to 0.(9) seconds after the interval. Below an example that fails (window not expired) majority of the times (window is expired only if it starts e.g. at 1634992063.4999 and is checked at 1634992065.5000 - withtime()
rounding it would be 3 seconds).