I have a python requests
-based suite of API tests that automatically retry every request with a 408 or 5xx response. I'm looking at re-implementing some of them in k6 for load testing. Does k6
have support for retrying http requests?
There is no such functionality in k6, but you can add it fairly simply by wrapping the k6/http functions like:
function httpGet(url, params) {
var res;
for (var retries = 3; retries > 0; retries--) {
res = http.get(url, params)
if (res.status != 408 && res.status < 500) {
return res;
}
}
return res;
}
And then just use httpGet
instead of http.get
;)