I tried writing simple code in Tests tab of a API request in postman tool to test rate limit of an API. Basically want to verify if n is X-Rate-Limit and if I call same API n+1 no. of times does it throw rate limit exceeded status code in response. Although I want to run these within a timeframe of ms (which X-RateLimit-Reset provides) however I'm not sure if that is achievable via postman. Also, running the below code is not working to verify the rate limit exceeded as the loop count is definitely running 20 times but not decreasing the count/value of rateRemaining in each iteration.
Any ideas or suggestions?
n = 20;
var rateRemaining = postman.getResponseHeader("X-RateLimit-Remaining");
while(n >= 0) {
console.log("Loop:" + n + " xRatelimitRemaining:" + rateRemaining);
postman.setNextRequest("List API to test rate limit");
counter--;
}
if(n === 0) {
console.log("Stop loop");
postman.setNextRequest(null);
tests["Verify rate limit exceeds"] = pm.response.to.have.status(429);
}