Code Monkey home page Code Monkey logo

hammer-time's Introduction

build status

hammer-time

Greenkeeper badge

Create a swarm of socket.io clients to stress test your socket-based application. Provides hooks to allow for HTTP based authentication to be passed into the socket connection requests if necessary, as well as listening to and responding to various socket events.

Install/Run

npm i -g hammer-time
hammer-time example.com --port 9000 --concurrent 50 --frequency 6000 --duration 100000 --generator my-gen.js

Usage

Usage: hammer-time [host] -p [port] -c [concurrency] -f [frequency] -d [duration] -g [generator]

Options:
  --version     Print the version number
  -p, --port        What port to use. Default = 80
  -c, --concurrent  How many clients to run concurrently. Default = 100
  -f, --frequency   Frequency of client messages (ms). Default = 50
  -d, --duration    Length of test (ms). Default = 60000 (1 minute)
  -g, --generator   Name of generator file to load, if any. This will specify
                    the details of how to connect and authenticate to your socket server
  -v, --verbose     Be extremely loud about what it is doing


Programmatic Access

hammer-time is also available as module that can be used outside of the scope of the CLI. (This is how the tests are run!). The arguments to the method are the same (and in the same order!) as the CLI, with the addition of an optional callback to be called when the tests are complete. The method returns an event emitter which you can use for monitoring the process. The CLI interface is a great example of how this works.

var ht = require('hammer-time');
ht(host, port, concurrent, frequency, duration, generator)
	.on('start', function(){
		console.log('hammer time is starting');
	})
	.on('error', function(err){
		console.log(err);
	});

Events

  • start โ†’ The client has started, but not asked any clients to yet connect
  • client-connected โ†’ A client has connected to the server and the handshake is complete. If you have an event named connect, in your exports.events object, that method will be called immediately after this message is emitted.
  • message โ†’ A client has sent a message to the server, the message is passed as an argument
  • disconnect โ†’ A client has disconnected from the server
  • end โ†’ hammer-time has run for the set duration
  • error โ†’ hammer-time encountered as an error. The error is passed as an argument

Generator

Generators allow you to set custom authentication methods, listeners for the socket, and what message(s) the client should send to flood the server.

The generator should export the following symbols (none of these are required, but it might not do much if you don't provide one).

See examples/default-generator.js for an example of how this works.

  • exports.events โ†’ object of functions where the key is the event name, and the value is the function to run for that event
{
  [eventname]: function(event name, cookies, username, password, message data, socket object, emitter returned from API)
}

The function's signature is:

/**
 * Respond to an event
 * @method event
 * @param  {string} the name of the event you're responding to
 * @param  {object} any cookies returned from your auth method
 * @param  {string} the username that was used for authenticating this socket
 * @param  {string} the password that was used for authenticating this socket
 * @param  {object} the message from the socket.io server
 * @param  {object} the socket client
 * @param  {object} the emitter returned from the function. Allows you to emit data to the CLI or other listeners
 */
  • exports.authenticate โ†’ function(host, port, iteration, cb)
/**
 * Authenticate for a client
 * @method  authenticate
 * @async
 * @param   {string} host hostname
 * @param   {integer} port portname
 * @param   {integer} iteration what client number to generate
 * @param   {Function} cb `err` on error, `err`, `cookies`, `username`, `password` on success
 * @returns {object} undefined
 */

note: cookies should be an object of parsed cookies, and username, password will be the credentials used to authenicate. If authenication fails, the callback should receive an error

  • exports.getSocketUrl โ†’ function(host, port, cookies)
/**
 * Returns the URL to send to the `io.connect` method.
 * @method  getSocketURL
 * @param   {string} host host name
 * @param   {integer} port port
 * @param   {object} cookies if you need them
 * @returns {string} The URL that should be passed to the socket.io constructor
 */
  • exports.clientIterateMessage โ†’ function(cookies, user, pass)
/**
 * Returns a message to send to the client
 * @method  clientIterateMessage
 * @param   {object} cookies Any cookies you might need
 * @param   {string} user the name of the user who authenciated
 * @param   {string} pass the password of the user who authenciated
 * @returns {object} The message you'd like to pass to the server, or `false` if there is no message
 */

License

Copyright ยฉ2014 Scripto, LLC. Available under the MIT license

hammer-time's People

Contributors

greenkeeper[bot] avatar toddself avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

sloops77

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.