def test_window_decorator_across_windows():
from time import monotonic, sleep
limiter = FixedWindowRateLimiter(SECONDS, 1)
@limiter.limit
def call():
t = monotonic()
sleep(SECONDS * 1.25)
return t
# This should take up two fixed windows for the first task, and the second shouldn't execute until the third (after 2 x SECONDS).
first = call()
second = call()
assert (SECONDS - EPSILON) * 3 >= second - first >= (SECONDS - EPSILON) * 2
##########################
# TokenBucketRateLimiter #
##########################
评论列表
文章目录