socket-stress-test
Version:
Enables you to create basic stress tests for sockets
74 lines (55 loc) • 2.45 kB
Markdown
This is a basic utility that you can use to do a stress test on your Socket IO Server.
To install this package you can run the following command:
```shell
npm install socket-load-tests
```
There are two ways to use the stress test. Option one is running it through your desktop, option two is running it through a different server. Here we show you how to use this package (works both for server and client side).
```nodejs
var SocketPromiseHandler = require('socket-stress-test')
socket_handler = new SocketPromiseHandler({
ioUrl: 'http://your-external-server:3000'
, connectionInterval: 1000 // Fire one each second
, maxConnections: 100 // Stop at having 100 connections
, ioOptions: {
transports: ['websocket'], // force only websocket (optional)
}
})
socket_handler.new(function(socketTester, currentConnections) {
// New connection comes in.
})
.disconnect(function(socketTester) {
// Connection is disconnected by socket
})
.addEmit('joinRoom', {
your: "data"
}, 200) // after 200
.addEmit('newMessage', {
other: "data"
}, 1000) // After 1000
.run()
```
The socket promis handler is the scheduler which you can use to send new emits. These emits will be distributed at the time each connection is made. All these emits will also be sequenced in a loop afterwards.
To add an event you can run `addEmit` with the eventKey, payload and delay. The delay is the delay after the previous emit.
Everytime a new connection is made the `new()` event callback is getting called.
This is the last thing you want to call before you have set up everything (all the `emits` etc.)
#### `stop()`
This is when you want to stop the stress test.
## Configuration
There is some configuration when you create a new `SocketPromiseHandler`:
- `ioUrl`: The Socket Server you want to test
- `maxConnections`: How many connection does the stress test go to
- `connectionInterval`: The interval of creating a new connection
- `ioOptions`: Extra options we put into the `socket.io-client`
## Testing
You can test the project by running the following command in the root folder:
```shell
npm test
```
__Note__: Testing has Dev dependencies, make sure those are installed.