goodlifeinc / shooter

https://www.npmjs.com/package/@genata/shooter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@genata/shooter

npm (scoped) npm bundle size (minified)

Simple stress load shooter. Sends asynchronous requests with shooting technique.
Aim it at targets, and shoot them.

Install

$ npm install @genata/shooter

Usage

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);
};

Api

  • setTimeout(Number) - in mileseconds
  • setError(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. After shoot() is performed same instance of Shooter can be reused for new aims.

Backlog features / TODOs

  • 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

About

https://www.npmjs.com/package/@genata/shooter


Languages

Language:TypeScript 100.0%