I am trying to use artillery to perf test a http-based socket endpoint. This is a real-time purchase system. My Virtual User (VU) will join a channel named join
with a GUID. On joining, the server sends to all VUs on the channel currentitem
, the current item being purchased or bid. It receives the data as a JSON (the current item and bids if any to it):
[
"currentitem",
{
"itemCode":999,
"itemCost":35,
"bid":{
"user":{
"code":"M001",
"name":"David"
},
"bidAmount":10
}
}
]
At this point, my script ought to read the JSON and extract the bidAmount
and increment it by 5 and send a bid back to the "bid" channel with the JSON:
[
"bid",
{
"user":{
"code":"J001",
"name":"John"
},
"itemCode":999,
"bidAmount":15
}
]
My Artillery YAML script is:
config:
target: 'https://example.com:8080/'
payload:
path: "users.csv"
fields:
- "code"
- "guid"
- "name"
phases:
- duration: 60
arrivalRate: 2
- engine: "socketio"
flow:
- emit:
channel: "join"
data: { "guid": "{{guid}}" }
- capture:
json: "$[1].bidAmount"
as: "latestBid"
- think: 2
- log: "{{name}} joined"
- engine: "socketio"
flow:
- loop:
- emit:
channel: "bid"
data: { "user": { "code": "{{code}}","name": "{{name}}" },"itemCode": 999,"bidAmount": {{latestBid+5}} }
- think: 1
- log: "Bid"
count: 720
My Q is: Artillery doesn't seem to be able to capture the socket messages back i.e. to get the bidAmount
. The docs don't show any way to do this too. Any idea how I can achieve that?
Apologies for the delay, we missed this question.
The issue with the above is that you're setting the requests in two different scenarios, so they'll be randomly picked according to weights. This means they never both run, and therefore won't set the variable.
The
socketio
engine allows you to specify HTTP requests within the same scenario. Here's an example of mixing http actions with socketio.Essentially all you have to do is put it within the same scenario (make sure to also set the
scenarios
key), and it should work!