r/learnjavascript • u/thisismugisha • 2d ago
How do you customize artillery load tests and create a more realistic simulation?
Artillery gives me detailed reports that I absolutely love. I can write a YAML script or use JavaScript. However, I'd like to do more with the scenarios instead of just "think for x seconds".
I want to test my socket.io server, and while I can write an emit, I'd like to use my seed data so that each virtual user sends a unique emit and has logic to process callbacks from the socket and listen to events.
For example, given the scenario (in JS) below:
{
name: "scenario 1",
engine: "socketio-v3",
flow: [
{
think: 1,
emit: [
{
channel: "channel",
data: [
{
one: "one",
two: two
}
]
}
],
acknowledge: {
match: {
three: {
four: 'string',
five: 'string',
six: {
seven: 'number',
eight: 'number'
},
nein: 'number'
},
dix: 'object'
}
},
think: thinkingTime
}
]
}I would prefer to manipulate the data sent, and while I still want to validate the acknowledgement, I'd still like to use the data received.
I want to do this, so I don't use think.
For further context, I am new to this and don't actually know what the "correct" procedure for testing actually is. I'm going on the assumption that the closer to reality a simulation is, the better, and so I want to use seed data to simulate what users will actually be able to do.
I never actually checked if think is enough and going for more realistic simulations is putting in effort for little reward.
Thank you kindly!
2
u/QueasyPrior6654 1d ago
A step with a nonzero think only pauses, so its emit and acknowledge get skipped. I'd put the pause in its own step. The socketio-v3 README uses a plain argument list,
emit: ["channel", { one: "{{ one }}" }]. Wrapped in an array, your channel/data object becomes the event name.A CSV under config.payload fills that {{ one }}, one row per new virtual user, random unless order is sequence, which wraps around. In acknowledge, match compares a json path to a value, so a type map checks nothing. Capture there with json and as puts a value in
context.vars. For a single ack object the path is $.three.nein. Does your server send one object to the ack?2
u/Discordbothost 1d ago
The socketio-v3 plugin has acknowledge.capture alongside match. If the first ack argument is an object with a roomId, capture $.0.roomId with as: roomId. Then use {{ roomId }} in the next emit to test that the second event uses the room the server just returned.