synthetic-monitoring-app
synthetic-monitoring-app copied to clipboard
Scripted checks produce no output after timeout
What happened:
With a multi-step scripted check, you want to set a reasonable timeout to prevent it from running too long if one step stall. When test executions hit a timeout we do not get any metric or log output. This can make it hard to understand how the timeout happened. Which step took too long?
Assuming the script partially completes, there should be useful information we can provide about the test exeuction
- Partial output of the steps that passed?
- Where/which step the timeout occurred?
What you expected to happen:
I would expect to see logs (and metrics if possible) for the partially completed test execution.
How to reproduce it (as minimally and precisely as possible):
If you set the timeout of this script to be 30 seconds, it will always fail.
It runs a loop 10x with a sleep of 4-5 seconds.
import { check, sleep } from 'k6'
import http from 'k6/http'
import {
randomIntBetween
} from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'
export default function main() {
const N = 10;
const sleepIntervals = [...Array(N).keys()].map( () => randomIntBetween(4, 5) );
sleepIntervals.forEach( (dur, i) => {
const res = http.get('http://test.k6.io/');
var str = `Step ${i+1}`;
console.log(`${str} will sleep for ${dur}`)
check(res, {
'got a 200': (r) => r.status === 200,
});
sleep(dur);
});
}
The dashboard for this check is empty as it produces no metrics.
The logs repeat the same 2 lines: "beginning check" and "check failed":
If instead I use this script, which uses a setTimeout() to fail the test after 30 seconds, and set the check timeout to 45 seconds. This script also fails 100% of the time, but get some logs and metrics for it that tells me what happened before the timeout:
script:
import { check, sleep, fail } from 'k6'
import { setTimeout } from 'k6/timers'
import http from 'k6/http'
import {
randomIntBetween
} from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'
export default function main() {
const N = 10;
setTimeout( () => fail("timeout reached"), 30000 );
const sleepIntervals = [...Array(N).keys()].map( () => randomIntBetween(4, 5) );
sleepIntervals.forEach( (dur, i) => {
const res = http.get('http://test.k6.io/');
var str = `Step ${i+1}`;
console.log(`${str} will sleep for ${dur}`)
check(res, {
'got a 200': (r) => r.status === 200,
});
sleep(dur);
});
}
Dashboard: