29 lines
595 B
Python
29 lines
595 B
Python
import asyncio
|
|
from time import time
|
|
|
|
import pytest
|
|
|
|
from leaky_bucket import LeakyBucketLimiter
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_duration() -> None:
|
|
async def test_function():
|
|
pass
|
|
|
|
|
|
limiter = LeakyBucketLimiter(10, 100)
|
|
await limiter.start()
|
|
|
|
start = time()
|
|
|
|
tasks = [asyncio.create_task(limiter.execute(test_function)) for i in range(20)]
|
|
|
|
results = await asyncio.gather(*tasks, return_exceptions=True)
|
|
|
|
end = time()
|
|
duration = end - start
|
|
|
|
assert duration < 2.1
|
|
|
|
for item in results:
|
|
assert isinstance(item, Exception) is False |