Skip to content

Conversation

@miladev95
Copy link
Contributor

Adds focused tests in tests/Redis/DurationLimiterTest.php for acquire(), tooManyAttempts(), clear(), block(), and window reset after decay.

@miladev95 miladev95 changed the title [12.x] Expand Redis DurationLimiter tests to improve coverage [12.x] Expand Redis DurationLimiter tests Nov 27, 2025
@taylorotwell
Copy link
Member

Do we have to actually use sleep? Can we fake the time travel?

@taylorotwell taylorotwell marked this pull request as draft November 27, 2025 16:18
@miladev95
Copy link
Contributor Author

Do we have to actually use sleep? Can we fake the time travel?

I investigated using Carbon time travel, but DurationLimiter uses PHP's native
time() function in its Redis Lua scripts, which Carbon::setTestNow() can't mock.

Tested both approaches:

  • With Carbon time travel: 2 tests fail
  • With sleep(): All tests pass

ConcurrentLimiterTest also uses usleep() for the same reason. The sleep()
approach accurately tests real Redis TTL behavior.

@miladev95 miladev95 marked this pull request as ready for review November 29, 2025 09:15
@taylorotwell taylorotwell merged commit 1e78dfb into laravel:12.x Nov 30, 2025
73 of 74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants