pythondjangotestingtastypiethrottling

Testing Django throttling


I'm throttling using TastyPie, but want to add a test to make sure it's working properly. Is there an easy way to simulate 100 requests in a Django test (or hopefully some easier method) to test this?


Solution

  • I'd recommend http://locust.io/, which is a great load testing tool.

    If you need an automated test, you could also spawn some threads, inside of which you hit a live test server using Django's LiveServerTestCase.

    If you're more concerned with the logic of your code than it's tolerance of concurrent calls, the best way might be to mock out the calls to datetime.now() or time.time() that appears in your throttle code, returning a predefined value. This let's you precisely control the conditions your throttle should act upon in a way you can't (or would be very difficult) with live concurrent requests.