Simple stress load shooter. Sends asynchronous requests with shooting technique.
Aim it at targets, and shoot them.
$ npm install @genata/shooter
const Shooter = require("@genata/shooter");
const params = require('./params');
const shooter = new Shooter();
shooter.setError(onError);
shooter.aim(15, 'get', 'https://www.google.com/');
shooter.aim(15, 'post', 'http://localhost:8002/api/v1/account', params.searchAccountParams);
shooter.shoot(afterShoot);
const onError = function (error) {
if (error.response && error.response.status != '400') {
return {
err: error.response.data.error.message
};
} else {
console.log(error);
return {
err: error.message
};
}
};
const afterShoot = data => {
const totalResponses = data.length;
data = data.filter(i => i);
const grouped = {};
grouped['totalErrors'] = data.length;
grouped['totalResponses'] = totalResponses;
grouped['byMessages'] = data.reduce((memo, next) => {
if (!memo[next.err]) memo[next.err] = 0;
if (typeof next.err === 'undefined') {
console.log(next);
}
memo[next.err] += 1;
return memo;
}, {});
console.log(grouped);
};
setTimeout(Number)
- in milesecondssetError(fn)
- callback when request returns error(4xx, 5xx HTTP Status codes)setSucecss(fn)
- callback when request returns success(2xx HTTP Status codes)shoot(fn)
- method that performs all "aimed" operations. It accepts optional callback function. Aftershoot()
is performed same instance ofShooter
can be reused for new aims.
- when aiming -- use {} options object
- define timeout between requests
- in options. give ability to save something in {instance}.saved with {k: 'cookie', v: value} structure
- provide options.inject to use something saved in request, with some kind of selector pattern. e.g. {headers: { cookie: 'cookie'}}
- provide methods to manually remove or override saved