Testing the quality of real-time Socket.io-client integration application focus mainly in how much traffic it can handle before falling over. No one capture interest about the quality of socket.io-client integration on the front-end, the reason would be, the UI plays its role in the last phase of application.
The Socket.io engine in Artillery lets us to send data to server and optionally wait for and verify responses that come in response.
loadTestChatApp.yaml
config: target: http://your.chatApp.link phases: - duration: 300 arrivalRate: 50 processor: "./getRandomIds.js" scenarios: - engine: socketio flow: - function: "setMessage" - emit: channel: send_message data: {sender: "{{ randomuidsender }}",receiver: "{{ randomuidreciver }}", text: "lets c {{ message }}"}
Here the emit channel is named as ‘send_message’ because at the code(developer end), a function is called to emit a socket this name itself. When we need to get some dynamic values of some variables, we can add use some javascript function to do so. The send_message takes parameters with name ‘sender’ , ‘receiver’ and ‘text’. The value of ‘randomuidsender’, ‘randomuidreciver’ and ‘message’ are taken from a javascript file named ‘getRandomIds,js’. The content of the js file can be written as:
getRandomIds.js
'use strict'; module.exports = { setMessage: setMessage }; var i= 0 const RANDOMID = [ 'a2iYSFeDJZzV', 'LVcqlcn0aslH', '4lxmwIqOhOUf', 'o5XZFPzdLYtU', 'of9J1gpaeSie', 's8Z5OsAatCL7', '1BDMyFZhMuXY', 'uGbyRJbv4Slm', 'HQhYrDaQGrSF', 'h2Y6DA4fHorL', 'jc3HPcYMctyt' ]; function setRandomUid(context, events, done) { return done(); } function setMessage(context, events, done) { i= i+1; context.vars.message = i; var indexsender = Math.floor(Math.random() * RANDOMID.length); context.vars.randomuidsender = RANDOMID[indexsender]; var indexreciver = Math.floor(Math.random() * RANDOMID.length); if(indexsender==indexreciver) { if(indexreciver>0) indexreciver=indexreciver-1; else indexreciver=indexreciver+1; } context.vars.randomuidreciver = RANDOMID[indexreciver]; return done(); }
In the yaml file, we have set a load of 50 users with a duration of 500 second . The yaml says that we are using ‘engine’ as socket.io, the target url(without or without port number) is given under config option. presently we have only one flow to emit socket for specific duration, we can also add some multiple flow with different phases , lets have a look to the yaml.
config: target: http://your-chatApp.com:8080 phases: - duration: 300 arrivalRate: 1 variables: greeting: ["hello", "goedemorgen", "добрый день", "guten tag", "bonjour", "hola"] processor: "./function.js" scenarios: - engine: socketio flow: - function: "setMessage" - emit: channel: send_message data: {sender: 3Hzki7ya3cDz, reciever: 0srVrMCwlPrv, text: "this is a {{ message }}"} - think: 1 - emit: channel: send_message data: {sender: 0srVrMCwlPrv, reciever: 3Hzki7ya3cDz, text: second msg} - think: 1 - emit: channel: "new_message" data: "this is new message {{ message }}" - loop: - function: "setMessage" - emit: channel: "new_message" data: "this is new message {{ message }}" - think: 10 count: 10 - think: 60
Suggestion are appreciated in the comments 😀
Be the first to comment.