{"id":139418,"date":"2018-09-22T07:02:07","date_gmt":"2018-09-22T07:02:07","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=139418"},"modified":"2018-09-22T07:02:07","modified_gmt":"2018-09-22T07:02:07","slug":"artillery-testing-a-chatsocket-io-application","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/","title":{"rendered":"Artillery- testing a chat(Socket.io) application"},"content":{"rendered":"<p>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.<br \/>\nThe Socket.io engine in Artillery lets us to send data to server and optionally wait for and verify responses that come in response.<\/p>\n<p>loadTestChatApp.yaml<\/p>\n<pre class=\"brush:xml\">config:\r\n  target: http:\/\/your.chatApp.link\r\n  phases:\r\n  - duration: 300\r\n    arrivalRate: 50\r\n  processor: \".\/getRandomIds.js\"\r\nscenarios:\r\n- engine: socketio\r\n  flow:      \r\n      - function: \"setMessage\"\r\n      - emit:\r\n          channel: send_message\r\n          data: {sender: \"{{ randomuidsender }}\",receiver: \"{{ randomuidreciver }}\", text: \"lets c {{ message }}\"}<\/pre>\n<p>Here the emit channel is named as &#8216;send_message&#8217; 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 &#8216;sender&#8217; , &#8216;receiver&#8217; and &#8216;text&#8217;. The value of\u00a0 &#8216;randomuidsender&#8217;, &#8216;randomuidreciver&#8217; and &#8216;message&#8217; are taken from a javascript file named &#8216;getRandomIds,js&#8217;. The content of the js file can be written as:<\/p>\n<p>getRandomIds.js<\/p>\n<pre class=\"brush:js\">'use strict';\r\nmodule.exports = {\r\n  setMessage: setMessage\r\n};\r\n\r\nvar i= 0\r\nconst RANDOMID = \r\n[\r\n  'a2iYSFeDJZzV',\r\n  'LVcqlcn0aslH',\r\n  '4lxmwIqOhOUf',\r\n  'o5XZFPzdLYtU',\r\n  'of9J1gpaeSie',\r\n  's8Z5OsAatCL7',\r\n  '1BDMyFZhMuXY',\r\n  'uGbyRJbv4Slm',\r\n  'HQhYrDaQGrSF',\r\n  'h2Y6DA4fHorL',\r\n  'jc3HPcYMctyt'\r\n];\r\n\r\nfunction setRandomUid(context, events, done)\r\n{\r\n\treturn done();\r\n}\r\n\r\nfunction setMessage(context, events, done) {\r\n  i= i+1;\r\n  context.vars.message = i;\r\n  var indexsender = Math.floor(Math.random() * RANDOMID.length);\r\n  context.vars.randomuidsender = RANDOMID[indexsender];\r\n\r\n  var indexreciver = Math.floor(Math.random() * RANDOMID.length);\r\n\r\n  if(indexsender==indexreciver)\r\n  {\r\n  \tif(indexreciver&gt;0)\r\n  \t\tindexreciver=indexreciver-1;\r\n  \telse\r\n  \t\tindexreciver=indexreciver+1;\r\n  }\r\n  context.vars.randomuidreciver = RANDOMID[indexreciver];\r\n  return done();\r\n}<\/pre>\n<p>In the yaml file, we have\u00a0 set a load of 50 users with a duration of 500 second . The yaml says that we are using &#8216;engine\u200b&#8217; 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.<\/p>\n<pre class=\"brush:js\">config:\r\n  target: http:\/\/your-chatApp.com:8080\r\n  phases:\r\n  - duration: 300\r\n    arrivalRate: 1\r\n  variables:\r\n    greeting: [\"hello\", \"goedemorgen\", \"\u0434\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c\", \"guten tag\", \"bonjour\", \"hola\"]\r\n  processor: \".\/function.js\"\r\nscenarios:\r\n- engine: socketio\r\n  flow:\r\n    - function: \"setMessage\"\r\n    - emit:\r\n        channel: send_message\r\n        data: {sender: 3Hzki7ya3cDz, reciever: 0srVrMCwlPrv, text: \"this is a {{ message }}\"}\r\n    - think: 1\r\n    - emit:\r\n        channel: send_message\r\n        data: {sender: 0srVrMCwlPrv, reciever: 3Hzki7ya3cDz, text: second msg}\r\n    - think: 1\r\n    - emit:\r\n          channel: \"new_message\"\r\n          data: \"this is new message {{ message }}\"\r\n      - loop:\r\n          - function: \"setMessage\"\r\n          - emit:\r\n              channel: \"new_message\"\r\n              data: \"this is new message {{ message }}\"\r\n          - think: 10\r\n        count: 10\r\n      - think: 60\r\n\r\n<\/pre>\n<p>Suggestion are appreciated in the comments \ud83d\ude00<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 <a href=\"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":94,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4312],"tags":[],"class_list":["post-139418","post","type-post","status-publish","format-standard","hentry","category-automation-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Artillery- testing a chat(Socket.io) application - Webkul Blog<\/title>\n<meta name=\"description\" content=\"Testing the quality of real-time Socket.io-client integration application focus mainly in how much traffic it can handle before falling over.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Artillery- testing a chat(Socket.io) application - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Testing the quality of real-time Socket.io-client integration application focus mainly in how much traffic it can handle before falling over.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-09-22T07:02:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Himanshu Chand\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Himanshu Chand\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/\"},\"author\":{\"name\":\"Himanshu Chand\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/08d4d0b31f228925099740afd668b50f\"},\"headline\":\"Artillery- testing a chat(Socket.io) application\",\"datePublished\":\"2018-09-22T07:02:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/\"},\"wordCount\":246,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"articleSection\":[\"Automation testing\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/\",\"url\":\"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/\",\"name\":\"Artillery- testing a chat(Socket.io) application - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2018-09-22T07:02:07+00:00\",\"description\":\"Testing the quality of real-time Socket.io-client integration application focus mainly in how much traffic it can handle before falling over.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Artillery- testing a chat(Socket.io) application\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/08d4d0b31f228925099740afd668b50f\",\"name\":\"Himanshu Chand\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/067d10770fdcc86d177164f68eb74b9528397b3a5fbf01970b6f6dfd48c64281?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/067d10770fdcc86d177164f68eb74b9528397b3a5fbf01970b6f6dfd48c64281?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Himanshu Chand\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/himanshu-chand168\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Artillery- testing a chat(Socket.io) application - Webkul Blog","description":"Testing the quality of real-time Socket.io-client integration application focus mainly in how much traffic it can handle before falling over.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/","og_locale":"en_US","og_type":"article","og_title":"Artillery- testing a chat(Socket.io) application - Webkul Blog","og_description":"Testing the quality of real-time Socket.io-client integration application focus mainly in how much traffic it can handle before falling over.","og_url":"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2018-09-22T07:02:07+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Himanshu Chand","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Himanshu Chand","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/"},"author":{"name":"Himanshu Chand","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/08d4d0b31f228925099740afd668b50f"},"headline":"Artillery- testing a chat(Socket.io) application","datePublished":"2018-09-22T07:02:07+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/"},"wordCount":246,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"articleSection":["Automation testing"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/","url":"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/","name":"Artillery- testing a chat(Socket.io) application - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2018-09-22T07:02:07+00:00","description":"Testing the quality of real-time Socket.io-client integration application focus mainly in how much traffic it can handle before falling over.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/artillery-testing-a-chatsocket-io-application\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Artillery- testing a chat(Socket.io) application"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/08d4d0b31f228925099740afd668b50f","name":"Himanshu Chand","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/067d10770fdcc86d177164f68eb74b9528397b3a5fbf01970b6f6dfd48c64281?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/067d10770fdcc86d177164f68eb74b9528397b3a5fbf01970b6f6dfd48c64281?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Himanshu Chand"},"url":"https:\/\/webkul.com\/blog\/author\/himanshu-chand168\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/139418","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/94"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=139418"}],"version-history":[{"count":8,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/139418\/revisions"}],"predecessor-version":[{"id":144086,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/139418\/revisions\/144086"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=139418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=139418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=139418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}