Testing throttling#

We believe that throttling is a part of the business requirements, so it must be tested. To help users with it, we provide several utilities:

Testing that an endpoint is throttled usually means driving it to its limit first. Sending the configured max_requests in a loop is slow for large rates such as 1000/hour. What do we do instead?

  1. We lower the max_requests value for the first throttle and increase the rate to be a hour. This way we can reliably and fastly test the expected behavior

  2. Next, we send several requests (max_requests controls this) that will hit the endpoint, assert that the response status matches success_status code

  3. Lastly, we assert that the final request hits the rate limit, we also assert that the headers match our modified rate limit

Examples:

Default Python’s testing framework:

Only the endpoint under test is affected; its throttling is restored afterwards.

There’s also a lower level API: