19 lines
1013 B
JavaScript
19 lines
1013 B
JavaScript
import http from 'k6/http';
|
|
import encoding from 'k6/encoding';
|
|
import { check, sleep } from 'k6';
|
|
export const options = { vus: 2, duration: '90s', thresholds: { checks: ['rate>0.95'] } };
|
|
const base = __ENV.BASE_URL || 'https://hl.agapov.space';
|
|
export function setup() {
|
|
const username = `hpa_${Date.now()}`;
|
|
const password = 'synthetic-autoscaling-password';
|
|
const response = http.post(`${base}/api/v1/users`, JSON.stringify({ username, display_name: 'HPA CPU test', password }), { headers: { 'Content-Type': 'application/json' } });
|
|
if (response.status !== 201) throw new Error(`registration: ${response.status}`);
|
|
return { authorization: `Basic ${encoding.b64encode(`${username}:${password}`)}` };
|
|
}
|
|
export default function (data) {
|
|
const response = http.post(`${base}/api/v1/auth/sessions`, null, { headers: { Authorization: data.authorization } });
|
|
check(response, { 'authenticated login': r => r.status === 201 });
|
|
// Keep one account below its 20 requests/s auth budget.
|
|
sleep(0.1);
|
|
}
|