How to test rate limits
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.
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
or the option -i interval (same as ping). Wait interval seconds between sending each request.
With only one request, it would have no effect.
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
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!
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.
Ops sorry. Indeed -i interval was not working as I expected 😓
So the current workaround is to simply use a shell script. Thanks.
I would also be interested in this sort of feature
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.
@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 Thank you so much!