chensenlai 10988628a0 语音房项目初始化 | 5 éve | |
---|---|---|
.. | ||
lib | 5 éve | |
node_modules | 5 éve | |
test | 5 éve | |
.npmignore | 5 éve | |
.travis.yml | 5 éve | |
README.md | 5 éve | |
package.json | 5 éve |
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:
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).
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.
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.
There is some configuration when you create a new SocketPromiseHandler
:
ioUrl
: The Socket Server you want to testmaxConnections
: How many connection does the stress test go toconnectionInterval
: The interval of creating a new connectionioOptions
: Extra options we put into the socket.io-client
You can test the project by running the following command in the root folder:
npm test
Note: Testing has Dev dependencies, make sure those are installed.