File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
packages/service-library/tests/redis Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -392,3 +392,31 @@ async def work_function() -> str:
392392 # Verify the exception was logged (not raised)
393393 assert "Unexpected error while releasing semaphore" in caplog .text
394394 assert "SemaphoreNotAcquiredError" in caplog .text
395+
396+
397+ async def test_with_large_capacity (
398+ redis_client_sdk : RedisClientSDK ,
399+ semaphore_name : str ,
400+ ):
401+ large_capacity = 100
402+ concurrent_count = 0
403+ max_concurrent = 0
404+
405+ @with_limited_concurrency (
406+ redis_client_sdk ,
407+ key = semaphore_name ,
408+ capacity = large_capacity ,
409+ )
410+ async def limited_function ():
411+ nonlocal concurrent_count , max_concurrent
412+ concurrent_count += 1
413+ max_concurrent = max (max_concurrent , concurrent_count )
414+ await asyncio .sleep (60 )
415+ concurrent_count -= 1
416+
417+ # Start tasks equal to the large capacity
418+ tasks = [asyncio .create_task (limited_function ()) for _ in range (large_capacity )]
419+ await asyncio .gather (* tasks )
420+
421+ # Should never exceed the large capacity
422+ assert max_concurrent <= large_capacity
You can’t perform that action at this time.
0 commit comments