-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery_rate_limit_test.js
More file actions
47 lines (38 loc) · 978 Bytes
/
Copy pathquery_rate_limit_test.js
File metadata and controls
47 lines (38 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import http from "k6/http";
import { check, sleep } from "k6";
/*
Test goal:
- Simulate multiple users
- Each user has its own rate-limit bucket
- Validate 200 vs 429 behavior
*/
export const options = {
scenarios: {
multi_user_test: {
executor: "constant-vus",
vus: 20, // 20 concurrent users
duration: "15s", // run for 15 seconds
},
},
};
export default function () {
// Each VU acts like a unique user
const userId = `user-${__VU}`;
const url = "http://127.0.0.1:8000/products/?category=electronics";
const params = {
headers: {
"X-User-Id": userId,
},
};
const res = http.get(url, params);
// Validate responses
check(res, {
"status is 200 or 429": (r) =>
r.status === 200 || r.status === 429,
"rate limit header exists": (r) =>
r.headers["X-RateLimit-Remaining"] !== undefined ||
r.status === 429,
});
// Small delay to allow token refill
sleep(0.2);
}