nic-6443 opened a new pull request, #13841:
URL: https://github.com/apache/apisix/pull/13841
### Description
`t/plugin/ai-rate-limiting.t` TEST 37 pipelines four requests against a
redis-policy route and expects the fourth to be rejected. It is racy:
`ai-rate-limiting` commits token usage from a log phase timer
(`limit-count-redis.log_phase_incoming` schedules `timer_at(0)`), so a request
can be evaluated against a budget that still looks unspent and the rejection
lands one request late.
```
TEST 37: redis policy shares counter and rejects the 4th request - status
code ok
got: '200'
expected: '503'
```
Pipelined requests leave no point at which to wait, so the block now sends
the four requests sequentially and waits for each one's usage to reach redis
before sending the next. Waiting for the commit beats sleeping a fixed amount:
it takes only as long as the commit actually needs, and a sleep sized for a
busy machine would eat into the rule's own time window.
The helpers go in `t/lib/test_redis.lua`, next to the `flush_all()` this
suite already uses — `connect` and `release` are factored out of `flush_single`
so both share them, and `connect` grew a `database` option because the route
under test keeps its counters in redis db 1.
Verified by delaying the commit in `limit-count-redis.lua` (`timer_at(0)` ->
`timer_at(0.3)`), which turns the race into a deterministic failure: TEST 37
fails on current `master` with exactly the mismatch above, and passes with this
change. The whole file passes locally either way once the delay is removed (218
subtests).
### Checklist
- [x] I have explained the need for this PR and the problem it solves
- [x] I have explained the changes or the new features added to this PR
- [x] I have added tests corresponding to this change
- [x] I have updated the documentation to reflect this change
- [x] I have verified that this change is backward compatible (If not,
please discuss on the [APISIX mailing
list](https://github.com/apache/apisix/tree/master#community) first)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]