test: add end-to-end and load verification
This commit is contained in:
131
scripts/load_test.js
Normal file
131
scripts/load_test.js
Normal file
@@ -0,0 +1,131 @@
|
||||
import http from 'k6/http';
|
||||
import { check } from 'k6';
|
||||
import { Counter } from 'k6/metrics';
|
||||
|
||||
|
||||
const accepted = new Counter(
|
||||
'cdr_accepted'
|
||||
);
|
||||
|
||||
const backpressure = new Counter(
|
||||
'cdr_backpressure'
|
||||
);
|
||||
|
||||
const unavailable = new Counter(
|
||||
'cdr_unavailable'
|
||||
);
|
||||
|
||||
const unexpected = new Counter(
|
||||
'cdr_unexpected'
|
||||
);
|
||||
|
||||
|
||||
const RATE = Number(
|
||||
__ENV.RATE || 1000
|
||||
);
|
||||
|
||||
const PRE_ALLOCATED_VUS = Number(
|
||||
__ENV.PRE_ALLOCATED_VUS || 250
|
||||
);
|
||||
|
||||
const MAX_VUS = Number(
|
||||
__ENV.MAX_VUS || 1000
|
||||
);
|
||||
|
||||
const DURATION = (
|
||||
__ENV.DURATION || '10s'
|
||||
);
|
||||
|
||||
const BASE_URL = (
|
||||
__ENV.BASE_URL ||
|
||||
'http://localhost:8000'
|
||||
);
|
||||
|
||||
|
||||
export const options = {
|
||||
discardResponseBodies: true,
|
||||
|
||||
scenarios: {
|
||||
ingestion: {
|
||||
executor: 'constant-arrival-rate',
|
||||
|
||||
rate: RATE,
|
||||
timeUnit: '1s',
|
||||
|
||||
duration: DURATION,
|
||||
|
||||
preAllocatedVUs: PRE_ALLOCATED_VUS,
|
||||
maxVUs: MAX_VUS,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
export default function () {
|
||||
const now = Math.floor(
|
||||
Date.now() / 1000
|
||||
);
|
||||
|
||||
const rawId =
|
||||
`k6-${__VU}-${__ITER}-${Date.now()}`;
|
||||
|
||||
const payload = JSON.stringify({
|
||||
raw_id: rawId,
|
||||
|
||||
src_ip: '10.240.12.1',
|
||||
|
||||
device_id:
|
||||
'310410998877665',
|
||||
|
||||
caller_num:
|
||||
'+14155552671',
|
||||
|
||||
svc: '4G_DATA',
|
||||
|
||||
up_bytes: 1024,
|
||||
down_bytes: 4096,
|
||||
|
||||
rat: 6,
|
||||
|
||||
lac: '4021',
|
||||
ci: '8812',
|
||||
|
||||
epoch_start: now,
|
||||
epoch_end: now + 300,
|
||||
});
|
||||
|
||||
const response = http.post(
|
||||
`${BASE_URL}/api/v1/cdr/raw`,
|
||||
payload,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type':
|
||||
'application/json',
|
||||
},
|
||||
|
||||
tags: {
|
||||
endpoint: 'cdr_ingest',
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (response.status === 202) {
|
||||
accepted.add(1);
|
||||
|
||||
} else if (response.status === 429) {
|
||||
backpressure.add(1);
|
||||
|
||||
} else if (response.status === 503) {
|
||||
unavailable.add(1);
|
||||
|
||||
} else {
|
||||
unexpected.add(1);
|
||||
}
|
||||
|
||||
check(response, {
|
||||
'accepted or gracefully rejected':
|
||||
(r) =>
|
||||
r.status === 202 ||
|
||||
r.status === 429,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user