test_ratelimits.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:merakicommons 作者: meraki-analytics 项目源码 文件源码
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 #
##########################
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号