/artillery-engine-socketio-v3

Socket.IO v3 engine for Artillery

Primary LanguageJavaScriptMozilla Public License 2.0MPL-2.0

artillery-engine-socketio-v3

npm version Test App

Socket.IO v3 & v4 engine for Artillery

Disclaimer

In addition to upgrading the Socket.IO lib to version 3/4 this engine also modifies the original YML API documented at artillery.io.

The emit action no longer supports the explicit options channel and data. Instead, it will accept a list or array of arguments that will be passed to the Socket.IO emit function. Ex:

scenarios:
  - engine: socketio-v3
    flow:
      - emit: ["join", "lobby"]
      # It can also can be written as    
      - emit:
        - join
        - lobby  

All other advance options like namespace and acknowledge can still be included alongside the emit action but not under it. Ex:

scenarios:
  - engine: socketio-v3
    flow:
      - emit: ["join", "lobby"]
        namespace: /nsp1

Install & Configure

Install with npm

npm install -D artillery-engine-socketio-v3

Install with yarn

yarn add -D artillery-engine-socketio-v3

Enable the socketio-v3 engine by listing it in config.engines. Ex:

config:
  target: "http://localhost:3000"
  phases:
    - duration: 5
      arrivalRate: 1
  engines:
   socketio-v3: {}

You may set Socket.IO client options in config.engines.socketio-v3. Ex:

config:
  target: "http://localhost:3000"
  phases:
    - duration: 5
      arrivalRate: 1
  engines:
    socketio-v3:
      query:
        token: secret-token

If you have socket.io-msgpack-parser enabled on your server, you need to enable this parser by setting parser option to msgpack:

config:
  target: "http://localhost:3000"
  phases:
    - duration: 5
      arrivalRate: 1
  engines:
    socketio-v3:
      parser: msgpack
      query:
        token: secret-token

In each scenario you must list the engine socketio-v3 as well. Ex:

scenarios:
  - name: My first scenario
    engine: socketio-v3
    flow:
      - emit: ["join", "lobby"]
      - emit: ["message", "lobby", "Hello World"]  

Testing socket connection and re-connections

Respects beforeRequest custom function hook which is fired before emit

config:
  processor: "./someFileWithSomeFunction.js"
scenarios:
  - engine: socketio-v3
    flow:
      - emit: ["join", "lobby"]
        beforeRequest: "someFunction"

someFileWithSomeFunction.js

function someFunction(requestParams, context, userEvents, next) {
  // do something
  return next();
}

There is an option reconnect which can be used to force a socket reconnection before emit is fired. Use together with setting extraHeaders on the context object to enable login flows.

config:
  processor: "./processor.js"
scenarios:
  - engine: socketio-v3
    flow:
      - emit: ["login", { username: "creds", password: "secretPword" }]
        response:
          on: "success"
          capture:
            json: "$.token"
            as: "token"
      - function: "setToken"
      - emit: ["join", "lobby"]
        reconnect: true
        namespace: /authorisedNamespace

processor.js

function setToken(context, userEvents, next) {
  context.extraHeaders = { 'x-auth-token': context.vars.token };
  return next();  
}

Changelog

Changelog

Roadmap

Roadmap board