Beispiel #1
0
 def do_nothing_with_throttle():
     nonlocal errors
     throttle = Throttle('test', 1, redis)
     try:
         throttle.run(do_nothing, waiting_timeout=0.05)
     except WaitingTimeoutError as wte:
         errors.append(wte)
Beispiel #2
0
def test_throttle_removes_garbage_token(redis: StrictRedis):
    throttle = Throttle('test', 1, redis)

    def do_nothing():
        time.sleep(0.1)

    garbage_token = throttle.wait(1.0)
    assert redis.zscore('redis_gt:test', garbage_token)
    throttle.run(do_nothing)
    assert not redis.exists('redis_gt:test')
Beispiel #3
0
def test_throttle_runs_function(redis):
    throttle = Throttle('test', 1, redis)
    done = False

    def do_something(a, b):
        nonlocal done
        time.sleep(0.1)
        done = True
        return a * b

    assert not done
    assert throttle.run(do_something, 3, 7) == 21
    assert done
    assert not redis.exists('redis_gt:test')
Beispiel #4
0
 def do_nothing_with_throttle():
     throttle = Throttle('test', 5, redis)
     throttle.run(do_nothing)
Beispiel #5
0
 def do_something_with_throttle():
     throttle = Throttle('test', 1, redis)
     throttle.run(do_something)
Beispiel #6
0
 def do_nothing_with_throttle2():
     throttle = Throttle('test2', 2, redis)
     throttle.run(do_nothing)