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.
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.
To use the Socket.io engine in an Artillery scenario, set the
engine attribute of a scenario definition to
Socket.io-specific configuration options that may be set in the config section of a test script.
Query parameters can be specified as a string or as a dictionary:
A custom path may be set.
In this example the virtual users will connect to the
admin namespace with the custom path
Extra headers may be passed with
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.
You can skip long-polling and specify that a websocket transport be used straightaway:
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 action supports the following basic attributes:
channel- the name of the Socket.io channel to emit to
data- the data to emit (as a string). Note that multiple arguments for emit are not supported yet.
namespace- optional namespace to use for this
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
- 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
data- match the response exactly to the value provided
match- match the response with a JSONPath expression; the value of
matchis expected to be an object with two attributes:
json(to specify the part of the response to compare) and
value(to specify the expected value)
HTTP and Socket.io actions can be combined in the same scenario (a common scenario when testing servers based on Express.js):
You can use
think to emulate clients connecting to the app and listening without sending anything themselves.