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

Exit code is zero if thresholds are not met #1526

Closed
u6f6o opened this issue Jun 30, 2020 · 5 comments
Closed

Exit code is zero if thresholds are not met #1526

u6f6o opened this issue Jun 30, 2020 · 5 comments
Labels

Comments

@u6f6o
Copy link

u6f6o commented Jun 30, 2020

Environment

Locally:

  • k6 version: k6 v0.25.1
  • OS and version: mac Os Catalina 10.15.2

Gitlab:

  • Docker image: loadimpact/k6:latest on gitlab-runner 12.9.1

Expected Behavior

According to https://k6.io/docs/using-k6/thresholds the exit code should be != 0 in case of thresholds that are not met:

If any of the thresholds had failed, the little green checkmark
✓ next to the threshold name (failed requests, http_req_duration) would have been a red cross ✗ instead, and k6 would have generated a non-zero exit code.

Actual Behavior

Exit code is 0

image

Steps to Reproduce the Problem

  1. Define a new loadtest with thresholds that are not met
  2. Check exit code
@u6f6o u6f6o added the bug label Jun 30, 2020
@mstoykov
Copy link
Collaborator

works for me ... I think you are mistaking checks and thresholds?
Can you provide an example script that fails, you can use https://test-api.k6.io or https://httpbin.test.k6.io/ :)

@u6f6o
Copy link
Author

u6f6o commented Jun 30, 2020

Thx for the fast response. Yes, I can. So there is the base.js file which looks like the following:

import {check} from "k6";
import http from "k6/http";
import {Rate, Trend} from 'k6/metrics';

export let trendRTT = new Trend('RTT');
export let contentOKRate = new Rate('Content OK');
export let crododileIds = ["1", "2", "FOOBAR"]

export function execute() {
    const crocodileId = crododileIds[Math.floor(Math.random() * crododileIds.length)]
    const url = 'https://test-api.k6.io/public/crocodiles/' + crocodileId + '/'
    const res = http.get(url);
    const contentOK = check(res, {
        "is status 200": (r) => r.status === 200
    });
    contentOKRate.add(contentOK);
    trendRTT.add(res.timings.duration);
}

And then there is the smoke.js file that imports the other js file (in my project there is also a load.js, stress.js file):

import {execute} from "./base.js";

export let options = {
    vus: 1,  // 1 user looping for 1 minute
    duration: '1m',
    thresholds: {
        'Content OK  ': ['rate>0.99']
    },
    throw: true
};

export default function() {
    execute();
}

When I execute this test, the thresholds are not met, yet the exit code is 0:

image

@u6f6o
Copy link
Author

u6f6o commented Jun 30, 2020

I think I found it. Idk why, but for some reason there are some extra spaces in 'Content OK ', when I remove them, everything works as expected. Sorry for the false alarm!

@u6f6o u6f6o closed this as completed Jun 30, 2020
@u6f6o
Copy link
Author

u6f6o commented Jun 30, 2020

The only thing I am wondering about. Would it make sense maybe to add a warning/error if a threshold id refers to something that actually does not exist?

@na--
Copy link
Member

na-- commented Jun 30, 2020

👍 We sort of know about this issue and some related ones: #1346, #961

The threshold handling code needs an overhaul and we intend to make one soon: #1443

but it's worth pointing out the current issue specifically, so I did it in #1443 (comment)

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

No branches or pull requests

3 participants