A pub-sub load tester for Nes. Designed to be used to write custom "realworld" like scenarios.
npm install --save anger
To use anger
, simply require it, and supply it some test scenario configuration.
const anger = require('anger')
const instance = anger({
url: 'http://localhost:3000',
subscription: '/greet', // the 'topic' to pub/sub test
connections: 1000, // 1000 clients connect
senders: 2, // 2 clients send messages
requests: 1000, // 2 clients send 1000 requests
responses: 10000, // expected number of responses (1000 connections responding to 1000 individual requests)
identifier: (payload) => payload.meta.id, // used to apply an id to messages in, which matches it to the corresponding request
trigger: (sender) => { // a function used to send a message to the server
sender.request({
method: 'POST',
path: '/h',
payload: {
id: ++uid // this is used to map the responses to the requests
}
})
return uid // must return the uid of the message sent
}
})
instance.on('end', (result) => {
// some stats are in result
})
Start an anger instance against a given target.
opts
: AnObject
with configuration information. Can contain the following attributes:url
: The base url of the hapi/nes server you want to test.subscription
: A topic to test.connections
: The number of connections to maintain to server. Each is an individual nes client.senders
: The number of connections that should be senders.responses
: The number of overall expected responses to be recieved during this run.auth
: AFunction
orObject
passed to the nes client for authentication. If aFunction
, it is passed theclient
andindex
of that client as params. Must return the auth object options. If anObject
, it must be passed the auth object options. auth object reference.identifier
: A function used to map some payload response data to a requests uid.trigger
: A function which is passed a nes client to emit a message to the server for testing. Must return some uid of a message sent.retryOpts
: An object which is passed to try-again to achieve exponential backoff for retries. Check the try-again docs for reference on how to use it.. Default values below:retries
: 8max
: 10000jitter
: 0.2factor
: 2min
: 100
Returns an instance/event emitter for tracking progress, etc.
Because an anger instance is an EventEmitter
, it emits several events. these are below:
error
: emitted on a error. The callback function will receive theerror
as the first parameter.connect
: emitted when all clients are connected to the server.subscribe
: emitted when all clients are subscribed to the server.trigger
: emitted when a sender is sending a 'request' message. The callback function will receive the requestsuid
as the first parameter.publish-events-recieved
: emitted when all connections receive the message 'response' sent from the server, in response to some triggered 'request'. The callback should receive theuid
for the event that triggered it.end
: emmited when testing finishes, with theresult
passed as the first parameter to the callback.
Check out the examples folder for a simple sample.
MIT. Copyright (c) Matteo Collina and David Mark Clements 2016.