Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify MQTT Version Support in README and Runtime Error #43

Open
irfanalmsyah opened this issue Jan 6, 2025 · 2 comments
Open

Clarify MQTT Version Support in README and Runtime Error #43

irfanalmsyah opened this issue Jan 6, 2025 · 2 comments

Comments

@irfanalmsyah
Copy link

The repository currently does not specify the MQTT version it supports. However, the xk6-mqtt plugin relies on the eclipse-paho/paho.mqtt.golang library, which only supports MQTT v3.

@pmalhaire
Copy link
Owner

Hello thank you for your proposal, I am not sure what you mean by Runtime Error in the title ?

@irfanalmsyah
Copy link
Author

Thank you for your feedback, and I apologize for not providing a more detailed explanation initially.

The "Runtime Error" I referred to in the title is related to the lack of meaningful error messages when issues occur during execution. For instance, if there is no broker running on the specified host/port and the script attempts to connect, the only error message displayed is:

{"value":{}}

Test case to reproduce the issue:

import {
    check
} from 'k6';

const mqtt = require('k6/x/mqtt');
const rnd_count = 2000;
let rnd = Math.random() * rnd_count;
let connectTimeout = 2000
let publishTimeout = 2000
let closeTimeout = 2000
const k6Topic = `test-k6-plugin-topic ${rnd} ${__VU}`;
const k6PubId = `k6-pub-${rnd}-${__VU}`;
const messageCount = 3;
const host = "localhost"; // purposefully no broker running to see connect error
const port = "1883";
let publisher = new mqtt.Client(
    [host + ":" + port],
    "",
    "",
    false,
    k6PubId,
    connectTimeout,
)
let err;
try {
    publisher.connect()
}
catch (error) {
    err = error
}
if (err != undefined) {
    console.error("publish connect error:", err)
}

export default function () {
    for (let i = 0; i < messageCount; i++) {
        let err_publish;
        try {
            publisher.publish(
                k6Topic,
                1,
                k6Message,
                false,
                publishTimeout,
            );
        } catch (error) {
            err_publish = error
        }
        check(err_publish, {
            "is sent": err => err == undefined
        });
    }
}

export function teardown() {
    publisher.close(closeTimeout);
}

Result:

xk6 build latest --with github.com/pmalhaire/xk6-mqtt@latest
./k6 run test.js
         /\      Grafana   /‾‾/  
    /\  /  \     |\  __   /  /   
   /  \/    \    | |/ /  /   ‾‾\ 
  /          \   |   (  |  (‾)  |
 / __________ \  |_|\_\  \_____/ 

ERRO[0000] publish connect error: {"value":{}}           source=console
     execution: local
        script: test.js
        output: -

     scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
              * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

ERRO[0000] publish connect error: {"value":{}}           source=console
ERRO[0000] publish connect error: {"value":{}}           source=console
ERRO[0000] publish connect error: {"value":{}}           source=console

     ✗ is sent
      ↳  0% — ✓ 0 / ✗ 3

     checks...............: 0.00% 0 out of 3
     data_received........: 0 B   0 B/s
     data_sent............: 0 B   0 B/s
     iteration_duration...: avg=3.29ms min=3.29ms med=3.29ms max=3.29ms p(90)=3.29ms p(95)=3.29ms
     iterations...........: 1     247.356501/s


running (00m00.0s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  00m00.0s/10m0s  1/1 iters, 1 per VU

I was expecting a more informative error message that could help identify the cause of the issue, such as a failure to connect to the broker, network issues, invalid credentials, or even in this case, the lack of support for MQTT v5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants