-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
=================================== FAILURES ===================================
____________ test_limiter_01[clock2-create_sqlite_bucket-True-None] ____________
clock = <pyrate_limiter.clocks.TimeAsyncClock object at 0x7fdfc6f4be00>
create_bucket = <function create_sqlite_bucket at 0x7fdfc6b83600>
limiter_should_raise = True, limiter_delay = None
@pytest.mark.asyncio
async def test_limiter_01(
clock,
create_bucket,
limiter_should_raise,
limiter_delay,
):
bucket = await create_bucket(DEFAULT_RATES)
factory = DemoBucketFactory(clock, demo=bucket)
limiter = Limiter(
factory,
raise_when_fail=limiter_should_raise,
max_delay=limiter_delay,
buffer_ms=1
)
bucket = BucketAsyncWrapper(bucket)
item = "demo"
logger.info("If weight = 0, it just passes thru")
acquire_ok, cost = await async_acquire(limiter, item, weight=0)
assert acquire_ok
assert cost <= 10
assert await bucket.count() == 0
logger.info("Limiter Test #1")
await prefilling_bucket(limiter, 0.3, item)
if not limiter_should_raise:
acquire_ok, cost = await async_acquire(limiter, item)
if limiter_delay is None:
assert cost <= 50
assert not acquire_ok
else:
assert acquire_ok
else:
if limiter_delay is None:
with pytest.raises(BucketFullException):
acquire_ok, cost = await async_acquire(limiter, item)
else:
acquire_ok, cost = await async_acquire(limiter, item)
assert cost > 350
assert acquire_ok
# # Flush before testing again
await flushing_bucket(bucket)
logger.info("Limiter Test #2")
await prefilling_bucket(limiter, 0, item)
if limiter_should_raise:
if limiter_delay == 500:
with pytest.raises(LimiterDelayException) as err:
await async_acquire(limiter, item)
assert err.meta_info["max_delay"] == 500
assert err.meta_info["actual_delay"] > 600
assert err.meta_info["name"] == item
elif limiter_delay == 2000:
acquire_ok, cost = await async_acquire(limiter, item)
assert acquire_ok
elif limiter_delay == Duration.MINUTE:
acquire_ok, cost = await async_acquire(limiter, item)
assert acquire_ok
else:
with pytest.raises(BucketFullException) as err:
await async_acquire(limiter, item)
else:
acquire_ok, cost = await async_acquire(limiter, item)
if limiter_delay == 500 or limiter_delay is None:
assert not acquire_ok
else:
assert acquire_ok
# Flush before testing again
await flushing_bucket(bucket)
logger.info("Limiter Test #3: exceeding weight")
> await prefilling_bucket(limiter, 0, item)
tests/test_limiter.py:165:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
limiter = <pyrate_limiter.limiter.Limiter object at 0x7fdfc40dced0>
sleep_interval = 0, item = 'demo'
async def prefilling_bucket(limiter: Limiter, sleep_interval: float, item: str):
"""Pre-filling bucket to the limit before testing
the time cost might vary depending on the bucket's backend
- For in-memory bucket, this should be less than a 1ms
- For external bucket's source ie Redis, this mostly depends on the network latency
"""
acquire_ok, cost = await async_acquire(limiter, item)
logger.info("cost = %s", cost)
> assert cost <= 50
^^^^^^^^^^
E AssertionError
tests/helpers.py:80: AssertionError
----------------------------- Captured stderr call -----------------------------
INFO:pyrate_limiter:SQLite db path: /usr/src/tmp/pyrate_limiter_RNn86.sqlite
INFO:pyrate_limiter.limiter_factory:table_name='pyrate-test-bucket-w4JSrGKZbH'
INFO:pyrate_limiter:If weight = 0, it just passes thru
WARNING:pyrate_limiter:async call made without an async bucket.
INFO:pyrate_limiter:Limiter Test #1
INFO:pyrate_limiter:cost = 0
INFO:pyrate_limiter:cost = 0
INFO:pyrate_limiter:cost = 0
INFO:pyrate_limiter:Limiter Test #2
INFO:pyrate_limiter:cost = 0
INFO:pyrate_limiter:cost = 0
INFO:pyrate_limiter:cost = 0
INFO:pyrate_limiter:Limiter Test #3: exceeding weight
INFO:pyrate_limiter:cost = 73
------------------------------ Captured log call -------------------------------
INFO pyrate_limiter:conftest.py:96 SQLite db path: /usr/src/tmp/pyrate_limiter_RNn86.sqlite
INFO pyrate_limiter.limiter_factory:limiter_factory.py:43 table_name='pyrate-test-bucket-w4JSrGKZbH'
INFO pyrate_limiter:test_limiter.py:109 If weight = 0, it just passes thru
WARNING pyrate_limiter:limiter.py:363 async call made without an async bucket.
INFO pyrate_limiter:test_limiter.py:115 Limiter Test #1
INFO pyrate_limiter:helpers.py:79 cost = 0
INFO pyrate_limiter:helpers.py:85 cost = 0
INFO pyrate_limiter:helpers.py:91 cost = 0
INFO pyrate_limiter:test_limiter.py:136 Limiter Test #2
INFO pyrate_limiter:helpers.py:79 cost = 0
INFO pyrate_limiter:helpers.py:85 cost = 0
INFO pyrate_limiter:helpers.py:91 cost = 0
INFO pyrate_limiter:test_limiter.py:164 Limiter Test #3: exceeding weight
INFO pyrate_limiter:helpers.py:79 cost = 73
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels