synthetic-monitoring-app icon indicating copy to clipboard operation
synthetic-monitoring-app copied to clipboard

k6 scripted check ignores thresholds for assertions

Open peterschretlen opened this issue 8 months ago • 0 comments

Using a threshold on checks with a k6 scripted check should cause tests to fail. The threshold value seems to be igored. Docs reference: https://grafana.com/docs/k6/latest/using-k6/thresholds/#fail-a-load-test-using-checks

How to reproduce it (as minimally and precisely as possible):

This scripted check will display 9 assertions in the dashboard, and at least one will fail most of the time. Using the threshold defined, the test execution should fail.

import { check } from 'k6';
import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';

export const options = {
  thresholds: {
    checks: [{ threshold: 'rate==1.0', abortOnFail: true }],
  },
};

export default function main() {
  const value = randomIntBetween(0,10)
  console.log(`value ${value}`);
  check(randomIntBetween(0,10), {
    'Less than 1': (r) => r < 1,
    'Less than 2': (r) => r < 2,
    'Less than 3': (r) => r < 3,
    'Less than 4': (r) => r < 4,
    'Less than 5': (r) => r < 5,
    'Less than 6': (r) => r < 6,
    'Less than 7': (r) => r < 7,
    'Less than 8': (r) => r < 8,
    'Less than 9': (r) => r < 9
  });
}

What happened:

Uptime and reachability are reported as 100%, even though assertions are failing

peterschretlen avatar May 30 '24 17:05 peterschretlen