Skip to content

Commit

Permalink
🐛 Fuck asyncio
Browse files Browse the repository at this point in the history
  • Loading branch information
BalconyJH committed Jan 10, 2025
1 parent 6c7b6cc commit e59d4ef
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions tests/test_utils/test_rate_limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,10 @@ async def test_func() -> None:


@pytest.mark.asyncio
async def test_concurrent_requests(limiter: RateLimiter) -> None:
"""Test concurrent request handling.
async def test_concurrent_requests():
limiter = RateLimiter(calls=3, period=0.5)

Args:
limiter: The rate limiter fixture
"""
semaphore = asyncio.Semaphore(2) # 限制并发数为2
semaphore = asyncio.Semaphore(2)
active_count = 0
max_active = 0

Expand All @@ -121,11 +118,10 @@ async def test_func() -> None:
await asyncio.sleep(0.01)
active_count -= 1

# 执行测试
tasks = [test_func() for _ in range(5)]
await asyncio.gather(*tasks)

assert max_active <= 2, f"并发请求数不应超过2,实际为 {max_active}"
assert max_active <= 2


@pytest.mark.asyncio
Expand Down

0 comments on commit e59d4ef

Please sign in to comment.