File tree Expand file tree Collapse file tree 1 file changed +10
-16
lines changed Expand file tree Collapse file tree 1 file changed +10
-16
lines changed Original file line number Diff line number Diff line change @@ -31,35 +31,29 @@ def test_general_functionality(rate, capacity):
31
31
consume_one ()
32
32
time .sleep (float (capacity ) / rate )
33
33
34
- # NOTE(kgriffs): This works because we can consume at a much
35
- # higher rate relative to the replenishment rate, such that we
36
- # easily consume the total capacity before a single token can
37
- # be replenished.
38
34
def consume_all ():
39
- for i in range (capacity + 3 ):
35
+ start = time .time ()
36
+ i = 0
37
+ while True :
40
38
conforming = consume_one ()
41
-
42
- # NOTE(kgriffs): One past the end should be non-conforming,
43
- # but sometimes an extra token or two can be generated, so
44
- # only check a couple past the end for non-conforming.
39
+ elapsed = time .time () - start
45
40
if i < capacity :
46
41
assert conforming
47
- elif i > capacity + 1 :
42
+ elif i > capacity + ( rate * elapsed ) :
48
43
assert not conforming
44
+ break
45
+ i += 1
49
46
50
47
# Check non-conforming after consuming all of the tokens
51
48
consume_all ()
49
+ start = time .time ()
52
50
53
51
# Let the bucket replenish 1 token
54
52
time .sleep (1.0 / rate )
55
53
assert consume_one ()
56
54
57
- # NOTE(kgriffs): Occasionally enough time will have elapsed to
58
- # cause an additional token to be generated. Clear that one
59
- # out if it is there.
60
- consume_one ()
61
-
62
- assert storage .get_token_count (key ) < 1.0
55
+ elapsed = time .time () - start
56
+ assert storage .get_token_count (key ) < (rate * elapsed )
63
57
64
58
# NOTE(kgriffs): Let the bucket replenish all the tokens; do this
65
59
# twice to verify that the bucket is limited to capacity.
You can’t perform that action at this time.
0 commit comments