Forum Discussion

Stalsy's avatar
Stalsy
Contributor
4 years ago
Solved

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 proper...
  • Stalsy's avatar
    Stalsy
    4 years ago

    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')
    }