Threshold status after the test

Hi,

how can I access the threshold status right after the test? I would like to make an API call based on the threshold status.

import http from 'k6/http';
import { sleep } from 'k6';

export const options = {
  thresholds: {
    http_req_duration: ['p(95)<250'],
  },
};

export default function () {
  http.get('https://test.k6.io');
  sleep(1);
}

export function handleSummary() {
  if (threshold.status == 'OK') {
    http.get('https://test.k6.io')
  }
  return 'stuff'
}

In the above example I would like to know how to “access” threshold status and what kind of responses can I get?

For this example, the solution would be:

export function handleSummary(data) {
  console.log(data.metrics.http_req_duration.thresholds['p(95)<250'].ok);
}

If you need to view or work with the format of the end-of-test summary, you can log the output like:

export function handleSummary(data) {

  return { 'raw-data.json': JSON.parse(data)};

}

You can take a quick look at the output format on the handleSummary docs.

You can also use or see https://jslib.k6.io/k6-summary/0.0.1/index.js - a module to process the summary data and output it to various formats.

thank you for the answer. I managed to figure out something similar:

function CheckThresholds(data, metric) {
    const res = data['metrics'][metric]['thresholds'] ? data['metrics'][metric]['thresholds'] : true
    return Object.values(res).every(obj => obj['ok'])
}

it covers all thresholds within a chosen metric, and if at least one is false we get false. :slight_smile: if all true we get true

thx to above I can send some API calls to testrail and report the results during the test.