# Socket Load Tests This is a basic utility that you can use to do a stress test on your Socket IO Server. ## Installation To install this package you can run the following command: ```shell npm install socket-load-tests ``` ## Usage 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() ``` ### Socket Promise Handler 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. #### `addEmit(eventKey, payload, delay)` To add an event you can run `addEmit` with the eventKey, payload and delay. The delay is the delay after the previous emit. #### `new(socketTester, currentConnections)` Everytime a new connection is made the `new()` event callback is getting called. #### `run()` 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.