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

Appearance settings

Commit 4965952

Browse filesBrowse files
committed
[RateLimiter] Resolve crash on near-round timestamps
1 parent 33d4c43 commit 4965952
Copy full SHA for 4965952

File tree

Expand file treeCollapse file tree

2 files changed

+10
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-1
lines changed

‎src/Symfony/Component/RateLimiter/Policy/SlidingWindow.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/RateLimiter/Policy/SlidingWindow.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,6 @@ public function getHitCount(): int
122122

123123
public function getRetryAfter(): \DateTimeImmutable
124124
{
125-
return \DateTimeImmutable::createFromFormat('U.u', $this->windowEndAt);
125+
return \DateTimeImmutable::createFromFormat('U.u', sprintf('%.6F', $this->windowEndAt));
126126
}
127127
}

‎src/Symfony/Component/RateLimiter/Tests/Policy/SlidingWindowTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/RateLimiter/Tests/Policy/SlidingWindowTest.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,13 @@ public function testGetRetryAfterUsesMicrotime()
102102
// should be 500ms left (10 - 9.5)
103103
$this->assertEqualsWithDelta(0.5, $window->getRetryAfter()->format('U.u') - microtime(true), 0.2);
104104
}
105+
106+
public function testCreateAtExactTime()
107+
{
108+
ClockMock::register(SlidingWindow::class);
109+
ClockMock::withClockMock(1234567890.000000);
110+
$window = new SlidingWindow('foo', 10);
111+
$window->getRetryAfter();
112+
$this->assertEquals('1234567900.000000', $window->getRetryAfter()->format('U.u'));
113+
}
105114
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.