Overview
Socket.io is a popular library for building real-time event-based applications. This page covers Socket.io testing functionality in Artillery provided by the built-in Socket.io engine.
Important - Socket.io server versions
The official Socket.io engine uses the v2 client, which may not work if you’re using Socket.io v3 on the server. Please see the v2 to v3 migration guide for more details.
We are working on adding support for Socket.io v3 in Artillery. In the meantime, if you need v3 support, please use artillery-engine-socketio-v3.
Enabling Socket.io support
To use the Socket.io engine in an Artillery scenario, set the engine
attribute of a scenario definition to socketio
.
scenarios: |
Socket.io-specific configuration
Socket.io-specific configuration options that may be set in the config section of a test script.
Query
Query parameters can be specified as a string or as a dictionary:
config: |
or:
config: |
Path
A custom path may be set.
In this example the virtual users will connect to the admin
namespace with the custom path mypath
.
config: |
Extra headers
Extra headers may be passed with extraHeaders
option:
config: |
Note: This only works if the default polling
transport is used. When other transports are used, extra headers won’t be taken into account by the server.
Transports
You can skip long-polling and specify that a websocket transport be used straightaway:
config: |
Scenario actions and configuration
The Socket.io engine allows for HTTP actions actions to be used in scenarios alongside emit
, which is the main Socket.io action. Looping with loop
and pausing execution with think
is also supported, see Testing HTTP for details.
emit
Sending Data
The emit
action supports the following basic attributes:
channel
- the name of the Socket.io channel to emit todata
- the data to emit (as a string). Note that multiple arguments for emit are not supported yet.namespace
- optional namespace to use for thisemit
Acknowledgements & Response Validation
Additionally, if you need to wait for an Socket.io acknowledgement response, or validate a response, the following attributes may also be used:
response
- optional object if you want to wait for a response:channel
- the name of the channel where the response is received.data
- the data to verify is in the response
acknowledge
- optional object if you want to wait for an acknowledgement
Notes:
- If you emit to a specific namespace, the response data is expected within the same namespace.
- Validating an acknowledgement response may be done by setting one of the following attributes on
acknowledge
:data
- match the response exactly to the value providedmatch
- match the response with a JSONPath expression; the value ofmatch
is expected to be an object with two attributes:json
(to specify the part of the response to compare) andvalue
(to specify the expected value)
Example
scenarios: |
Mixing in HTTP Actions
HTTP and Socket.io actions can be combined in the same scenario (a common scenario when testing servers based on Express.js):
config: |
Connecting Without Sending Any Data
You can use think
to emulate clients connecting to the app and listening without sending anything themselves.
config: |