hurl icon indicating copy to clipboard operation
hurl copied to clipboard

How to test rate limits

Open gugen-otsuki opened this issue 3 years ago • 11 comments

Problem to solve

I want to test rate limits in my APIs but I don't know how. More specifically, I want to test an API returns 200 if it has passed more than a specific duration since the last successful call, otherwise returns 429. I read the documentation but could not get an idea of how to achieve it. I am sorry if I am missing something.

gugen-otsuki avatar Jan 05 '23 05:01 gugen-otsuki

Hi @gugen-otsuki I'm not sure we can test that fully within Hurl. For the time-being, you may have to use a shell script that run hurl twice with a sleep between.

We could maybe add an option like --delay DURATION that could apply a delay before running each request. To apply to specific requests, we would use the existing Option section

[Options]
delay: DURATION

fabricereix avatar Jan 05 '23 08:01 fabricereix

or the option -i interval (same as ping). Wait interval seconds between sending each request. With only one request, it would have no effect.

fabricereix avatar Jan 05 '23 08:01 fabricereix

Thanks for your reply. I could not find delay option in the documentation. Where can I find it?

or the option -i interval (same as ping). Wait interval seconds between sending each request.

Thanks. I will try -i interval.

It would be nice if I can insert sleep between requests as follows:

GET https://example.com/api
HTTP/1.1 200

sleep 10s

GET https://example.com/api
HTTP/1.1 429

gugen-otsuki avatar Jan 05 '23 08:01 gugen-otsuki

I extracted tests that test rate limits to a separate file and ran it with -i interval, and it worked as I expected. Thanks for your help!

gugen-otsuki avatar Jan 05 '23 08:01 gugen-otsuki

Options delay or interval do not exist yet, it was just a suggestion. I also thought about the simple sleep command, but it does fit into an existing section. We need to think about it.

fabricereix avatar Jan 05 '23 08:01 fabricereix

Ops sorry. Indeed -i interval was not working as I expected 😓

gugen-otsuki avatar Jan 05 '23 09:01 gugen-otsuki

So the current workaround is to simply use a shell script. Thanks.

gugen-otsuki avatar Jan 05 '23 09:01 gugen-otsuki

I would also be interested in this sort of feature

softprops avatar Feb 07 '23 21:02 softprops

Related, curl support --rate max <request rate> and --limit-rate <speed>:

  • --rate 10/m: If curl is told to allow 10 requests per minute, it will not start the next request until 6 seconds have elapsed since the previous transfer was started
  • --limit-rate 100K: specify the maximum transfer rate you want curl to use - for both downloads and uploads.

--rate: can be easily implemented in Hurl (without using libcurl binding). --limit-rate can be implemented using the already provided libcurl binding.

I like also an interval/delay/wait simple option to make millisecond delays between request.

See #1222.

jcamiel avatar Feb 08 '23 09:02 jcamiel

@gugen-otsuki @softprops --delay option (in command line for every requests or per request with [Options]) has been added in the incoming 4.1.0 Hurl version.

jcamiel avatar Sep 21 '23 11:09 jcamiel

@jcamiel Thank you so much!

gugen-otsuki avatar Sep 21 '23 11:09 gugen-otsuki