Is there a way to count the request timeouts somehow rather than having them show in total sum of failed requests .
Hi @rdt.one
Yes, it is possible to output the console with a high timeout. Example:
import { check } from 'k6';
import http from 'k6/http';
export default function() {
const res = http.get('https://k6.io');
if (res.timings.duration > 3.0) { // 3.0 - time in second
console.log('timeout');
}
@PaulM That is not exactly what I was looking for. I was looking for a short way to represent request timeouts at the end test summary console output.
I did managed to implement it via custom Rate metric.
export function validateResponse(response, endpoint, trend) {
let status = response.status;
if (status === 0) { // k6 sets status code to '0' for timeout requests
timeouts.add(true);
fail('Request timeout for ' + endpoint);
} else if (status >= 500 && status <= 600) {
server_error.add(true);
fail('Server error happened for ' + endpoint);
} else if ( !(status === 200 || status === 204))
{
unsuccessful.add(true);
fail('API did not return successful response for ' + endpoint + '. Status code was: ' + status);
} else {
trend.add(response.timings.duration);
}
}
2 Likes