ctsit/redi — pull request #117 by ufl-taeber (2014-11-24 21:58:18+00:00)
Title: Fix a big flaw in the Throttle algorithm

Mohan discovered during his testing that the new throttling algorithm
was not working and that my new code was causing our IP to be banned. I
found that the code was fundamentally flawed and wrote some additional
unit tests to make sure it works correctly.

Basically, by clearing the deque after sleeping, I was essentially
assuming--quite wrongly--that all timestamps were at least as old as the first
one. This exact opposite of which is true.

Now, _wait() will only remove old entries from the deque, instead of all
of them, once the rate limit is hit.

Note: users should still probably set their rate limits to a few less
than the REDCap Rate Limit (default=600) to compensate for other web
requests which count against them in addition to RED-I's API calls. A
known example is PyCap's API calls when instantiating a Project object.