39 lines
958 B
JavaScript
39 lines
958 B
JavaScript
import autocannon from 'autocannon';
|
|
|
|
const base = process.env.LOAD_BASE_URL || 'http://127.0.0.1:4000';
|
|
const target = new URL(base);
|
|
|
|
if (target.hostname !== 'localhost' && target.hostname !== '127.0.0.1') {
|
|
console.error('This load test only runs against localhost');
|
|
process.exit(1);
|
|
}
|
|
|
|
/**
|
|
* @param {import('autocannon').Options} options
|
|
*/
|
|
function run(options) {
|
|
return new Promise((resolve, reject) => {
|
|
autocannon(options, (error, result) => {
|
|
if (error) {
|
|
reject(error);
|
|
return;
|
|
}
|
|
|
|
console.log(
|
|
`${options.method || 'GET'} ${options.url} ${result.requests.average} req/s, non-2xx ${result.non2xx}`,
|
|
);
|
|
resolve();
|
|
});
|
|
});
|
|
}
|
|
|
|
await run({ url: `${base}/api/health`, duration: 3, connections: 5 });
|
|
await run({
|
|
url: `${base}/api/applications`,
|
|
method: 'POST',
|
|
headers: { 'content-type': 'application/json' },
|
|
body: JSON.stringify({}),
|
|
duration: 3,
|
|
connections: 5,
|
|
});
|