Skip to content

Commit 82ebcb0

Browse files
committed
chore: add tests for handling same timestamp
Signed-off-by: Sihyeon Jang <[email protected]>
1 parent 58c34f1 commit 82ebcb0

File tree

2 files changed

+112
-1
lines changed

2 files changed

+112
-1
lines changed

t/plugin/limit-count-redis-cluster-sliding.t

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,60 @@ passed
186186
[200,200,200]
187187
188188
189+
=== TEST 5: redis-cluster policy with sliding window - enforce N per window under burst traffic
190+
--- config
191+
location /t {
192+
content_by_lua_block {
193+
local t = require("lib.test_admin").test
194+
local code, body = t('/apisix/admin/routes/10',
195+
ngx.HTTP_PUT,
196+
[[{
197+
"uri": "/burst-cluster",
198+
"plugins": {
199+
"limit-count": {
200+
"count": 3,
201+
"time_window": 2,
202+
"window_type": "sliding",
203+
"rejected_code": 503,
204+
"key": "remote_addr",
205+
"policy": "redis-cluster",
206+
"redis_cluster_nodes": [
207+
"127.0.0.1:5000",
208+
"127.0.0.1:5001"
209+
],
210+
"redis_cluster_name": "redis-cluster-1"
211+
}
212+
},
213+
"upstream": {
214+
"nodes": {
215+
"127.0.0.1:1980": 1
216+
},
217+
"type": "roundrobin"
218+
}
219+
}]]
220+
)
221+
222+
if code >= 300 then
223+
ngx.status = code
224+
end
225+
ngx.say(body)
226+
}
227+
}
228+
--- response_body
229+
passed
230+
231+
232+
=== TEST 6: redis-cluster policy with sliding window - only N requests allowed in a burst
233+
--- pipelined_requests eval
234+
[
235+
"GET /burst-cluster",
236+
"GET /burst-cluster",
237+
"GET /burst-cluster",
238+
"GET /burst-cluster",
239+
"GET /burst-cluster",
240+
"GET /burst-cluster"
241+
]
242+
--- error_code eval
243+
[200, 200, 200, 503, 503, 503]
244+
245+

t/plugin/limit-count-redis-sliding.t

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ passed
184184
[200,200,200]
185185
186186
187-
188187
=== TEST 5: setup route with fixed window for boundary burst comparison
189188
--- config
190189
location /t {
@@ -445,3 +444,58 @@ req 5: status=404, limit=10, remaining=5, has_reset=true
445444
--- response_body
446445
passed
447446
447+
448+
=== TEST 11: redis policy with sliding window - enforce N per window under burst traffic
449+
--- config
450+
location /t {
451+
content_by_lua_block {
452+
local t = require("lib.test_admin").test
453+
local code, body = t('/apisix/admin/routes/10',
454+
ngx.HTTP_PUT,
455+
[[{
456+
"uri": "/burst",
457+
"plugins": {
458+
"limit-count": {
459+
"count": 3,
460+
"time_window": 2,
461+
"window_type": "sliding",
462+
"rejected_code": 503,
463+
"key": "remote_addr",
464+
"policy": "redis",
465+
"redis_host": "127.0.0.1",
466+
"redis_port": 6379,
467+
"redis_timeout": 1000
468+
}
469+
},
470+
"upstream": {
471+
"nodes": {
472+
"127.0.0.1:1980": 1
473+
},
474+
"type": "roundrobin"
475+
}
476+
}]]
477+
)
478+
479+
if code >= 300 then
480+
ngx.status = code
481+
end
482+
ngx.say(body)
483+
}
484+
}
485+
--- response_body
486+
passed
487+
488+
489+
=== TEST 12: redis policy with sliding window - only N requests allowed in a burst
490+
--- pipelined_requests eval
491+
[
492+
"GET /burst",
493+
"GET /burst",
494+
"GET /burst",
495+
"GET /burst",
496+
"GET /burst",
497+
"GET /burst"
498+
]
499+
--- error_code eval
500+
[200, 200, 200, 503, 503, 503]
501+

0 commit comments

Comments
 (0)