-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindexer.js
More file actions
69 lines (63 loc) · 1.73 KB
/
Copy pathindexer.js
File metadata and controls
69 lines (63 loc) · 1.73 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import http from "k6/http";
import { check, sleep } from "k6";
import { textSummary } from "https://jslib.k6.io/k6-summary/0.0.2/index.js";
/**
* Load test for the ILN Indexer API.
* Closes #47
*/
const BASE_URL = __ENV.BASE_URL || "http://localhost:8080";
export const options = {
scenarios: {
// Scenario 1: 50 concurrent users hitting pending invoices for 30s
pending_invoices: {
executor: "constant-vus",
vus: 50,
duration: "30s",
exec: "getPendingInvoices",
},
// Scenario 2: 100 concurrent users hitting a single invoice for 30s
single_invoice: {
executor: "constant-vus",
vus: 100,
duration: "30s",
exec: "getSingleInvoice",
},
// Scenario 3: Ramp up from 1 to 200 users over 60 seconds
ramp_up: {
executor: "ramping-vus",
startVUs: 1,
stages: [{ duration: "60s", target: 200 }],
exec: "getSingleInvoice",
},
},
thresholds: {
// p95 response time under 200ms
http_req_duration: ["p(95)<200"],
// error rate under 1%
http_req_failed: ["rate<0.01"],
},
};
export function getPendingInvoices() {
const res = http.get(`${BASE_URL}/invoices?status=Pending`);
check(res, {
"status is 200": (r) => r.status === 200,
});
sleep(1);
}
export function getSingleInvoice() {
// Using invoice ID 1 as a placeholder for testing
const res = http.get(`${BASE_URL}/invoice/1`);
check(res, {
"status is 200": (r) => r.status === 200,
});
sleep(1);
}
/**
* Generates a summary report in JSON format saved to tests/load/results/
*/
export function handleSummary(data) {
return {
stdout: textSummary(data, { indent: " ", enableColors: true }),
"tests/load/results/summary.json": JSON.stringify(data),
};
}