Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a retry helper method to k6-util #5

Closed
simskij opened this issue Apr 7, 2020 · 1 comment
Closed

Add a retry helper method to k6-util #5

simskij opened this issue Apr 7, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@simskij
Copy link
Contributor

simskij commented Apr 7, 2020

https://community.k6.io/t/retry-http-requests/190 has gotten a bit of attention in the forums (230 views in roughly 8 months) which suggest it's something our users would like to have access to.

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;
}

was posted by @mstoykov as a suggestion on how to implement it yourself as a user. i'm thinking that we could provide a generic retry function in the k6-util lib that takes an http request function as a callback and attempt count as arguments, like

retry(
  () => http.get(url, params),
  retryCount,
);

// we could allow users to override the accepted status code by supplying an optional third argument:

retry(
  () => http.get(url, params), 
  retryCount, 
  [200, 301]
);
@simskij simskij added the enhancement New feature or request label Apr 7, 2020
@simskij simskij closed this as completed Jun 27, 2023
@metaturso
Copy link

Hi @simskij, this issue is marked as completed, but none of the Grafana K6 documentation mentions anything about a retry function. Was this function ever added to K6 itself?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants