nic-6443 commented on code in PR #13212:
URL: https://github.com/apache/apisix/pull/13212#discussion_r3071776951


##########
t/plugin/limit-count5.t:
##########
@@ -253,3 +253,55 @@ nginx_config:
 --- error_code: 200
 --- access_log eval
 
qr/\{\\x22rate_limiting_key\\x22:\\x22\/apisix\/routes\/1:\d+:test\.com\\x22,\\x22rate_limiting_limit\\x22:2,\\x22rate_limiting_remaining\\x22:1,\\x22rate_limiting_reset\\x22:10}/
+
+
+
+=== TEST 8: cost=0 peek does not consume quota
+--- config
+    location = /t {
+        content_by_lua_block {
+            local limit_count_local = require 
"apisix.plugins.limit-count.limit-count-local"
+            local lim = limit_count_local.new("plugin-limit-count", 5, 60)
+            local uri = ngx.var.uri
+            local conf = {
+                time_window = 60,
+                count = 5,
+            }
+
+            -- peek with cost=0, should show remaining=5 (full quota)
+            local delay, remaining = lim:incoming(uri, true, conf, 0)
+            ngx.say("peek1: ", remaining)
+
+            -- another peek should still show remaining=5
+            local delay, remaining = lim:incoming(uri, true, conf, 0)
+            ngx.say("peek2: ", remaining)
+
+            -- commit with cost=2
+            local delay, remaining = lim:incoming(uri, true, conf, 2)
+            ngx.say("commit1: ", remaining)
+
+            -- peek again should show remaining=3
+            local delay, remaining = lim:incoming(uri, true, conf, 0)
+            ngx.say("peek3: ", remaining)
+
+            -- commit with cost=3 (exhausts quota)
+            local delay, remaining = lim:incoming(uri, true, conf, 3)
+            ngx.say("commit2: ", remaining)
+
+            -- peek on exhausted quota should show remaining=0
+            local delay, remaining = lim:incoming(uri, true, conf, 0)
+            ngx.say("peek4: ", remaining)

Review Comment:
   Good catch — updated the peek calls to use `commit=false` to match the 
actual dry_run path in `init.lua`. The expected remaining values are identical 
since `dict:get(key) or 0` (commit=false) produces the same consumed count as 
`dict:incr(key, 0, 0, window)` (commit=true) for these scenarios.



-- 
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]

Reply via email to