k6

Retry http requests

Is there a way using k6/http lib to retry http requests returning specific response codes?
Say, I’d like to retry for up to 3 times all requests that return a 408 or 5xx.

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 :wink: