ptejada / artillery-engine-socketio-v3

Socket.IO v3 engine for Artillery
Mozilla Public License 2.0
22 stars 15 forks source link

acknowledge failed #12

Closed exodia0x closed 1 year ago

exodia0x commented 1 year ago
          acknowledge:
          capture:
            json: "$.protocol"
            as: "ack"
      - log: "Acknowledgement == {{ack}}"

Form the code I When i emit message with ' channel : "command" and event: "command"'. I got message "Acknowledgement == {"value":"","failed":true}" but i check socket.io server emit was success. How to Fix it this is example acknowledge result with json type

      {
    "protocol": {
        "version": "1",
        "command": "ack",
        "invoke": "1",
        "qos": "normal",
    }
}
ptejada commented 1 year ago

Can you include more lines about your example? Like the full emit action from the yml example.

Any snippet of the equivalent JS client and server actions you are trying to test might be helpful as well.

exodia0x commented 1 year ago

Example Artillery code. emit data with json type

config:
  target: "https://Domain.com"
  phases:
    - duration: 1
      arrivalRate: 1
  engines:
   socketio-v3:
    extraHeaders: 
      key: "Testing"
    transports: ["websocket"]

scenarios:
  - name: " > Send Message and Check Respond == ACT scenario"
    engine: socketio-v3
    flow:
      - emit:
          channel: "command"
          event: "command"
          data:
            protocol:
              version: "1"
              command: "service"
              subCommand: "init1"
              invoke: "1234"
              qos: "test"
              topic: "test123"
              token: "token1234"
              service: "ODA"
              diagMessage: ""
            header:
              version: "1.0"
              timestamp: "2023-05-01T14:51:06.157Z"
              orgService: "1234"
              tid: "1234"
              lastTid: "1234"
              session: "1234"
              transaction: "1234"
              communication: "unicast"
              groupTags: []
              identity:
                device: "1234"
              tmfSpec: "1234"
              baseApiVersion: "1234"
              schemaVersion: "1234"
            body: {}
        acknowledge:
          capture:
            json: "$.protocol"
            as: "ack"
      - log: "Acknowledgement == {{ack}}"

Server Script i cant show it.

ptejada commented 1 year ago

Hello,

An easy way to troubleshoot this is to print or log the data your receiving on your server. I didn't mean for you to share your whole server code, but at least how you are listening for the event.

Another thing you can try is capturing everything to see what you are getting back:

   capture:
       json: "$"
       as: "ack"

Then you can log the {{ack}} like you were doing.

About your emit action, the emit.event setting is not a valid option so it won't be sent to server. Only emit.channel and emit.data will be sent. With that being said this two explicit options are part of the legacy API. Use the array syntax instead, which allows you to send as many arguments as your want.

For example, if this is how you are listening to the event on the server

socket.on('command', (event, data, ack) => ack(data))

Then you want to send three separate params to the server. Ex:

...
      - emit:
          - command
          - event
          - protocol:
              version: "1"
               ...
            header:
              version: "1.0"
              ....
            body: {}
...

I hope this helps.

exodia0x commented 1 year ago

I try with

   capture:
       json: "$"
       as: "ack"

But still show "Acknowledgement == {"value":"","failed":true}". About socket.on('command', (event, data, ack) =>ack(data))

It can you in artillery yaml ? i just saw that code for .js file running with node

ptejada commented 1 year ago

@exodia0x

You may not understand the YML syntax correctly yet. {"value":"","failed":true} is something your server is sending. Most likely because you are not sending the right payload. Consider this example if you were the use the JS syntax to emit something from the Socket.IO client

socket.emit("hello", { a: "b", c: [] });

The equivalent of this in YML would be this

...
      - emit:
          - hello
          - { a: "b", c: [] }
...
exodia0x commented 1 year ago

Sorry, Im really new for that. I try to change code likes this if i set - event script error not emit

      - emit:
          - command
          - { "protocol": { "version": "1", "command": "service", " .............. }}

and

...
      - emit:
          - command
          - protocol:
              version: "1"
               ...
            header:
              version: "1.0"
              ....
            body: {}
...

But i still got "Acknowledgement == {"value":"","failed":true}". However how to debug in artillery about what they send message to server that will make easier to fix it. and I try to running with nodejs file got ack back ex code as below

  const payloadFE = {
    protocol: {
      version: "1",
      command: "service",
      subCommand: "init1",
      invoke: "1",
      qos: "normal",
      topic: "testinggg",
      token: "tesringng",
      service: "testapp",
      diagMessage: "",
    },
    header: {
      version: "1.0",
      timestamp: "2023-05-04T14:51:06.157Z",
      orgService: "test",
      tid: "1234",
      lastTid: "1234",
      session: "1234",
      transaction: "1234",
      communication: "unicast",
      groupTags: [],
      identity: {
        device: "123444",
      },
      tmfSpec: "123444",
      baseApiVersion: "11111.0.0",
      schemaVersion: "11111.0.0",
    },
    body: {},
  };

  and

    socket.emit("command", payloadFE, (ack) => {
    console.log("Acknowledgement received:", ack);

Got Ack back like

  Acknowledgement received: {"protocol":{"version":"1","command":"ack","invoke":"1","qos":"normal","topic":"testtttt","token":"testtoekn","service":"MBE01","diagMessage":"OK"}}

Did you have any way to open debug in artillery ?

ptejada commented 1 year ago

Without a minimal reproducible example, it will be hard to help you here since you know your application best. You can enable all sorts of debugging output in most Node applications with the DEBUG environment variable. For example, using DEBUG=* will print all debug logs from all libraries used in Artillery. However, that will probably generate a lot of noise.

If you want only to enable the debug logs for the Socket.IO client try DEBUG=socket.io-client*. So you will basically precede your command with this env variable definition. Ex:

DEBUG=socket.io-client* npx artillery run my-test.yml
exodia0x commented 1 year ago

form debug i got ack message form server but show form socket.io-client:socket calling ack 0 with "MESSAGE ............." what i need to config it form yaml to capture it

image

Now i try to capture with $[0].protocol / $.[0] / $.0.protocol / $.ack[0]

Still got failed: true again

ptejada commented 1 year ago

You are receiving the JSON document as a string. It might be double JSON encoded.

I have put up a simple example for you to can compare

image

https://stackblitz.com/edit/stackblitz-starters-qgzgrb?file=test.yml&view=editor

exodia0x commented 1 year ago

You are receiving the JSON document as a string. It might be double JSON encoded.

I have put up a simple example for you to can compare

image

https://stackblitz.com/edit/stackblitz-starters-qgzgrb?file=test.yml&view=editor

Thank you, I will try to capture with string type or any way to convert ack to json format? Nad did you have any way for when client emit and still connection socket server until reach to duration time and all disconnect. Now i use "think" for that. Ex My Duration 300s(5m) and set i think to 300s at the end of ack match. But when running loadtesting will +5m for waiting last client group that generate connection reach to 5m and disconnect. and on result Min / Max / Medium / p95 / p99 show like this

image
ptejada commented 1 year ago

I am not sure how you can capture and decode the JSON string. However, if you are manually encoding and seconding packets in your application, it might be redundant.

As for the session length table, it looks good based on the 300-second wait time you have configured. The output is shown in milliseconds. If you want to have some variance, use the jitter option.

- think: 300   # seconds
  jitter: 5000 # milliseconds

I am closing this ticket since we figured out why you were having trouble capturing a JSON doc prop and the problem is the ack from your server is sending back a string.