test_ratelimits.py 文件源码

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

项目:merakicommons 作者: meraki-analytics 项目源码 文件源码
def test_windowed_bucket_decorator_timing():
    from time import monotonic

    limiter = WindowedTokenBucketRateLimiter(SECONDS, PERMITS, BURST, TOKENS)

    @limiter.limit
    def call():
        return monotonic()

    times = []
    for _ in range(VALUE_COUNT):
        times.append(call())

    frequency = SECONDS / PERMITS

    first_time = times[0]
    expected_times = [first_time]
    for i in range(1, len(times)):
        expected_times.append(first_time + i * frequency)

    epsilon = 0.04
    for i, time in enumerate(times):
        assert expected_times[i] - epsilon <= time <= expected_times[i] + epsilon
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号