Files

56 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2026-08-26 06:41:07 +08:00
import http from 'k6/http';
import exec from 'k6/execution';
import { check } from 'k6';
import { SharedArray } from 'k6/data';
const fixtures = new SharedArray('privacy delete fixtures', () => JSON.parse(open(__ENV.FIXTURE_FILE)));
const vus = Number(__ENV.VUS || fixtures.length);
export const options = {
scenarios: {
concurrent_privacy_deletes: {
executor: 'per-vu-iterations',
vus,
iterations: 1,
maxDuration: '30s',
gracefulStop: '5s',
},
},
thresholds: {
http_req_failed: ['rate==0'],
http_req_duration: ['p(95)<1000'],
checks: ['rate==1'],
},
};
export default function () {
const fixture = fixtures[exec.vu.idInTest - 1];
const response = http.post(
`${__ENV.API_BASE}/api/v1/subjects/${fixture.subject_id}/privacy-requests`,
JSON.stringify({
request_type: 'DELETE',
scope: {},
reason: 'synthetic concurrent privacy capacity verification',
confirmation: fixture.preferred_name,
}),
{
headers: {
Authorization: `Bearer ${__ENV.ACCESS_TOKEN}`,
'Content-Type': 'application/json',
'Idempotency-Key': `privacy-capacity-${fixture.subject_id}`,
},
tags: { name: 'POST privacy delete' },
},
);
check(response, {
'delete accepted': (r) => r.status === 202,
'request id returned': (r) => {
try {
return Boolean(r.json('data.id'));
} catch (_) {
return false;
}
},
});
}