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 for Artillery uses the v2.x client, which may not work if you’re using Socket.IO v3.x and above on the server. Please see the v2.x to v3.x migration guide for more details.
We are working on adding support for Socket.IO v3.x in Artillery. In the meantime, if you need v3.x 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
Query parameters can be specified as a string or as a dictionary:
A custom path may be set with the
In the following example, the virtual users will connect to the
admin namespace with the custom path
Extra headers may be passed with
You can skip long-polling by using the
transports option to specify WebSocket transport:
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 attributes:
channel- The name of the Socket.IO channel to emit an event.
data- The data to emit as a string.
namespace- Optional namespace to use for emitting the event.
Additionally, if you need to wait for an Socket.IO acknowledgement response or validate a response, you can also use the following attributes:
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.
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. This attribute expects an object with two attributes:
json- The part of the response to compare.
value- The expected value.
Emit a single event:
Emit an event and validate a response:
Emit an event and validate an acknowledgement:
Emit data to a namespace:
A single scenario can combine both HTTP and Socket.IO actions.
The following example is 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.
If you’re having issues getting your test scenarios to complete successfully, you can print out helpful debugging messages using the
DEBUG environment variable.
DEBUG=socketio when running your tests to view any errors that occurred during the test run.
On macOS and Linux systems, you can temporarily set the
DEBUG environment variable by setting its value when running your Artillery test script:
DEBUG=socketio artillery run my-script.yaml
For the Windows Command Prompt, you first need to set the
DEBUG environment variable using the
set command before running the test script:
If you use PowerShell on Windows, you can set the
DEBUG environment variable using
$Env:DEBUG before running the test script:
$Env:DEBUG = 'socketio'