Search⌘ K
AI Features

Testing Our Rate Limiter

Explore the process of testing a rate limiter in Go by creating functions that simulate multiple concurrent API calls to a backend service. Understand how to verify successful requests and detect when the rate limiter blocks excess calls, ensuring the backend can handle traffic within set concurrency limits.

Rate limiters will limit the number of concurrent requests we can process at a given time. Let’s write a test case for the same to check whether our rate limiter works as expected.

Making our API call

First, we will create a function that can make an API call to our server. We would want to know whether the API call succeeded and whether we received a 200 response. If we received a 429 response instead, it would imply that our rate limiter had kicked in! Our function will also accept a count to keep track of ...