npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stressful-journey

v2.3.2

Published

A tool for stess testing user journeys through APIs

Downloads

10

Readme

node-stressful-journey

Build Status

A tool for stress testing user journeys through APIs

Installation

npm install -g stressful-journey

Configuration

To execute a stress test, you need to provide the journey to test. This is specified as a JS module which exports an array of steps (see test/example.js for an example).

type: 'request'

The most common step is a request. An HTTP request will be issued and the step will only succeed if the status code is 200, the content-type is application/json and the response is valid JSON. A simple example is -

  {
    type: 'request',
    options: 'http://localhost/hello'
  }

The options value is passed to http.request. N.B. options.agent will always be set to false to prevent connection pooling.

It is also possible to specify a factory method if you want to e.g. template the URL -

  var prefix = 'http://localhost/hello';
  // ...
  options: function(ctx) {
    return prefix + '/hello';
  }

The function will be called once per simulated user per run. The ctx argument is described below.

If you want to post data or modify the request in other ways, you can specify a function as the request value -

  {
    type: 'request',
    options: {
      hostname: 'localhost',
      path: '/echo',
      method: 'POST'
    },
    request: function(ctx, req) {
      req.setHeader('Content-Type', 'application/json');
      req.end(JSON.stringify({hello:'world'}));
    }

The req argument is an http.ClientRequest. N.B. you must manually req.end() the request if you provide a request value otherwise the request will not be sent.

Likewise if you want to validate the JSON response you can specify a function as the response value -

  {
    type: 'request',
    options: 'http://localhost/hello',
    response: function(ctx, res) {
      if (res.hello !== 'world') {
        throw new Error('Failed to validate response');
      }
    }
  }

The res argument is an http.IncommingMessage. Any errors thrown here will be recorded and cause the step to fail.

It is also possible to specify a custom timeout for the request -

  {
    type: 'request',
    timeout: 1000, // ms
    options: 'http://localhost/hello'
  }

If not specified a default value of 60 seconds will be used.

type: 'wait'

A wait step causes the journey to pause for the specified duration of milliseconds -

  {
    type: 'wait',
    duration: 100
  }

duration also accepts a function -

  {
    type: 'wait',
    duration: function(ctx) {
      return ctx.stepIndex * 100;
    }
  }

type: 'custom'

A custom step simply calls the configured handler -

  {
    type: 'custom',
    handler: function(ctx) {
      // do something
    }
  }

Any errors thrown here will be recorded and cause the step to fail.

Also supports async operation if a second argument is specified by the handler. In this case errors should be specified as the argument to the callback.

ctx

ctx is an object unique to each simulated user which can be used to store values between steps or functions within a step. The following properties are automatically added -

  • uuid - a RFC4122 v4 UUID
  • index - the index of the simulated user
  • stepIndex - the index of the currently executing step
  • step - the currently executing step (i.e. ctx.steps[ctx.stepIndex])
  • deltas - an array of timing results for the steps completed so far

Other supported types are wait and custom, see the code (src/handlers) for usage.

Running

Once you have a journey defined, you can run the stress test using -

stressful-journey journey.js [count=1] [delay=0] [randomisation=0]
  • count - the number of users to simulate
  • delay/ransomisation - allows control of ramp-up (1 - Math.random() * randomisation) * delay