How to throttle test (get HTTP 429 status code)
I'm using ReadyAPI 3.6 Test. I need to test all non-200 HTTP status codes. For 429 (too many requests) I've tried using a data-driven approach with the data source just populating a constant property, then the call to the API and then a groovy script to check and stop the execution if n iterations have been achieved (otherwise the test will loop indefinitely).
But even when I clone the test a couple of times and put it in its own testsuite and run the test suite in parallel mode, ReadyAPI seems to wait till each request returns and I never get HTTP status 429. Even when we dropped the throttling count to 1 per second, all that happened was that the call just took longer that a second to complete! So from 120ms average time per call, I got an average of 1.2 seconds so again, no HTTP 429!
Thanks for the quick replies. It's working now. I think there was an issue with the throttling limit. To answer your questions: I did try the load testing but you can't really see the results, this is one of many automated tests that I'm running so I need a clear pass/fail indication.
When you use a Data Source, you must use a Data Source Loop to get iterations but in my case since I don't know how many iterations will occur before the 429 return code, I set up an infinite loop and the groovy script checks for an early exit if I get a 429. If I don't get 429 after 100 iterations I consider the test a failure.
My solution consists of the following:
1. Data Source step that sets a property
2. REST request that uses the property
3. REST request that uses the property
4. REST request that uses the property
5. REST request that uses the property
6. Groovy script to decide pass/fail
7. Data Source Loop with target the first REST request
The groovy script checks the current row, and also the Status response headers of the 4 REST requests.
If the row is less than 100 and if any of the 4 statuses are 429 then the test finishes successfully. If after 100 iterations there is no 429 the test fails.
Sample code:
def row = testRunner.testCase.testSteps["Data Source"].currentRow
if (row <= 100 )
{
if (responseHeaders1.get('#status#').toString().contains('429') || responseHeaders2.get('#status#').toString().contains('429') ||responseHeaders3.get('#status#').toString().contains('429') ||responseHeaders4.get('#status#').toString().contains('429') ){
testRunner.cancel('Finished Successfully')
}
}
else {
testRunner.fail('Finished UNSuccessfully')
}