diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index b70746d..dfa83d6 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -2,9 +2,9 @@ name: Go on: push: - branches: [ main, remake_apis ] + branches: [ main ] pull_request: - branches: [ main, remake_apis ] + branches: [ main ] jobs: build_n_test: @@ -15,7 +15,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.18 + go-version: '1.20' - name: Install xk6 run: go install go.k6.io/xk6/cmd/xk6@latest @@ -47,7 +47,7 @@ jobs: steps: - uses: actions/setup-go@v3 with: - go-version: 1.18 + go-version: '1.20' - uses: actions/checkout@v3 - name: golangci-lint uses: golangci/golangci-lint-action@v3 \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index 119c408..3c40dff 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -75,4 +75,5 @@ linters: - stylecheck - funlen - gocognit - fast: false \ No newline at end of file + - depguard + fast: false diff --git a/README.md b/README.md index c65bdd1..0f511c5 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,95 @@ This is a [k6](https://go.k6.io/k6) extension using the [xk6](https://github.com | :exclamation: This is a proof of concept, isn't supported by the k6 team, and may break in the future. USE AT YOUR OWN RISK! | | ---------------------------------------------------------------------------------------------------------------------------- | -This project is a k6 extension that can be used to load test Mqtt. Per each connection to Mqtt, many messages can be sent. These messages are an array of strings. There is also a consumer for testing purposes, i.e. to make sure you send the correct data to Mqtt. The consumer is not meant to be used for testing Mqtt under load. - -In order to build the source, you should have the latest version of Go (go1.15) installed. I recommend you to have [gvm](https://github.com/moovweb/gvm) installed. +This project is a k6 extension that can be used to load test Mqtt. +Per each connection to Mqtt, many messages can be sent. These messages are an array of strings. +There is also a consumer for testing purposes, i.e. to make sure you send the correct data to Mqtt. +The consumer is not meant to be used for testing Mqtt under load. ## k6 version -This extension is uptodate with k6 version v0.38.0 (breaking change) previous version is tagged at tag v0.37.0 +This extension is tested with k6 version `v0.43.1` last release is [v0.39.2](https://github.com/pmalhaire/xk6-mqtt/releases/tag/v0.39.2). + + +## Build & Run + +If you want to contribute and improve this extension (you are welcome !) see Build for development section. + +If your are only interrested to use this extension and write your own js tests this section is for you. +It only requieres docker. + +Run the following commands. + +```bash +# 1. Create path for k6 (here my_k6_path) +mkdir my_k6_path +# 2. Build the k6 binary including the extension in the current path with +docker run --rm -it -u "$(id -u):$(id -g)" -v "${PWD}:/xk6" grafana/xk6 build v0.43.1 --with github.com/pmalhaire/xk6-mqtt@v0.39.1 +# 3. Run a sample mqtt server +docker run --rm --name mosquitto -d -p 1883:1883 eclipse-mosquitto mosquitto -c /mosquitto-no-auth.conf +# 4. Get a test sample test.js file +wget -O test.js https://raw.githubusercontent.com/pmalhaire/xk6-mqtt/main/examples/test.js +# 5. Run the test for 10s +./k6 run --vus 50 --duration 10s test.js +``` + +Your extension is working. + +You are ready to customize +- replace the `mqtt server` you want to test (step 3) +- write the specifics things you want to test in your `my_test.js` file (step 4) + + +sample output: + +```bash +./k6 run --vus 50 --duration 10s test.js + + /\ |‾‾| /‾‾/ /‾‾/ + /\ / \ | |/ / / / + / \/ \ | ( / ‾‾\ + / \ | |\ \ | (‾) | + / __________ \ |__| \__\ \_____/ .io + + execution: local + script: test.js + output: - + + scenarios: (100.00%) 1 scenario, 50 max VUs, 40s max duration (incl. graceful stop): + * default: 50 looping VUs for 10s (gracefulStop: 30s) + -## Build + ✓ is publisher connected + ✓ is subcriber connected + ✓ is sent + ✓ message received + ✓ is content correct + + █ teardown + + checks.........................: 100.00% ✓ 447007 ✗ 0 + data_received..................: 0 B 0 B/s + data_sent......................: 0 B 0 B/s + iteration_duration.............: avg=12.31ms min=514.49µs med=3.36ms max=79.2ms p(90)=44.25ms p(95)=46.17ms + iterations.....................: 40637 4044.417556/s + mqtt.received.bytes............: 5253945 522901.478829/s + mqtt.received.messages.count...: 121911 12133.252667/s + mqtt.sent.bytes................: 5253945 522901.478829/s + mqtt.sent.messages.count.......: 121911 12133.252667/s + vus............................: 50 min=50 max=50 + vus_max........................: 50 min=50 max=50 + + +running (10.0s), 00/50 VUs, 40637 complete and 0 interrupted iterations +default ✓ [======================================] 50 VUs 10s +``` + +## Build for development + +If you need to edit the code of this extension. + +You should have the latest version of Go (go1.20) installed. +I recommend you to have [gvm](https://github.com/moovweb/gvm) installed. To build a `k6` binary with this extension, first ensure you have the prerequisites: @@ -27,12 +107,7 @@ Then, install [xk6](https://github.com/grafana/xk6) and build your custom k6 bin $ go install go.k6.io/xk6/cmd/xk6@latest ``` -2. Build the binary: from latest version - ```shell - $ xk6 build --with github.com/pmalhaire/xk6-mqtt@latest - ``` - -3. Build the binary: from source code + Build the binary: from source code ```shell git clone github.com/pmalhaire/xk6-mqtt cd xk6-mqtt