Giter Club home page Giter Club logo

Comments (2)

minhhoangvn avatar minhhoangvn commented on July 17, 2024 1

I got the same issue and i am very appreciate if anyone knows how to work around it.

from artillery-core.

NHP95 avatar NHP95 commented on July 17, 2024

For anyone who got into the same issue, I kinda found a way to work around this problem by making use of JavaScript.

{
  "config": {
    "target": "http://localhost:8000",
    "phases": [
      {
        "duration": 1,
        "arrivalRate": 1
      }
    ],
    "processor": "./custom_processor_metric.js",
    "variables": {
      "channelId": "1f49b260-94eb-41e2-8f9f-fca20ba9fc96",
      "channelToken": "ad09a6b1-19ea-47a1-9b8d-b2c0f42f0a98",
      "recipientId": "ad09a6b1-19ea-47a1-9b8d-b2c0f42f0a98",
      "senderId": ""
    },
    "socketio": {
      "transports": [
        "websocket"
      ]
    }
  },
  "scenarios": [
    {
      "name": "Scenario 1",
      "engine": "socketio",
      "flow": [
        {
          "function": "initConversation"
        },
        {
          "function": "sendMessage"
        },
        {
          "function": "sendMessage"
        },
        {
          "function": "sendMessage"
        }
      ]
    },
    {
      "name": "Scenario 2",
      "engine": "socketio",
      "flow": [
        {
          "function": "initConversation"
        },
        {
          "function": "sendMessage"
        }
      ]
    }
  ]
}

Given the script above, I used JS function instead of directly emitting the message to serve. With this approach, you have to manually verify the response yourself.

module.exports = {
    initConversation: initConversation,
    sendMessage: sendMessage
};

const artillery = require('artillery-core');

function initConversation(context, events, done) {
    events.emit("request");
    let startedAt = process.hrtime();
    context.sockets["/"].emit("message",
        {
            "action": "START_NEW_CONVERSATION", "dataType": "UNK", "data": {}, "conversationInfo": { "channelId": context.vars.channelId, "channelToken": context.vars.channelToken, "recipientId": context.vars.recipientId, "chatId": null, "senderId": null }
        });
    return processSender(context, events, done, startedAt);
}

function processSender(context, events, done, startedAt) {
    context.sockets["/"].on("message", function (res) {
        try {
            context.vars.senderId = res.conversationInfo.senderId;
        } catch (error) { // do something
        }

        if (context.vars.senderId) {
            markEndTime(events, context, startedAt);
            context.sockets["/"].off("message");
            return done();
        }
    });
}

function sendMessage(context, events, done) {
    events.emit("request");
    const startedAt = process.hrtime();
    context.sockets["/"].emit("message",
        {
            "action": "UNK", "dataType": "TEXT", "data": "Hello from JS", "conversationInfo": { "channelId": context.vars.channelId, "channelToken": context.vars.channelToken, "recipientId": context.vars.recipientId, "chatId": context.vars.channelId + '-' + context.vars.senderId, "senderId": context.vars.senderId }
        });
    return waitForResponse(context, events, done, startedAt, startTime);
}

function waitForResponse(context, events, done, startedAt, startTime) {
    context.sockets["/"].on("message", function (res) {
        if (res.action == "UNK") {
            markEndTime(events, context, startedAt);
            context.sockets["/"].off("message");
            return done();        
        }
    });
}

function markEndTime(ee, context, startedAt) {
    let endedAt = process.hrtime(startedAt);
    let delta = (endedAt[0] * 1e9) + endedAt[1];
    ee.emit('response', delta, 0, context._uid);
}

from artillery-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.