@@ -81,7 +81,7 @@ async def test_semaphore_initialization(
8181 )
8282
8383
84- async def test_semaphore_invalid_capacity_raises (
84+ async def test_invalid_semaphore_initialization (
8585 redis_client_sdk : RedisClientSDK ,
8686 semaphore_name : str ,
8787):
@@ -95,6 +95,23 @@ async def test_semaphore_invalid_capacity_raises(
9595 redis_client = redis_client_sdk , key = semaphore_name , capacity = - 1
9696 )
9797
98+ with pytest .raises (ValueError , match = "TTL must be positive" ):
99+ DistributedSemaphore (
100+ redis_client = redis_client_sdk ,
101+ key = semaphore_name ,
102+ capacity = 1 ,
103+ ttl = datetime .timedelta (seconds = 0 ),
104+ )
105+ with pytest .raises (ValueError , match = "Timeout must be positive" ):
106+ DistributedSemaphore (
107+ redis_client = redis_client_sdk ,
108+ key = semaphore_name ,
109+ capacity = 1 ,
110+ ttl = datetime .timedelta (seconds = 10 ),
111+ blocking = True ,
112+ blocking_timeout = datetime .timedelta (seconds = 0 ),
113+ )
114+
98115
99116async def test_semaphore_acquire_release_single (
100117 redis_client_sdk : RedisClientSDK ,
@@ -216,7 +233,7 @@ async def test_semaphore_blocking_timeout(
216233 redis_client = redis_client_sdk ,
217234 key = semaphore_name ,
218235 capacity = capacity ,
219- timeout = timeout ,
236+ blocking_timeout = timeout ,
220237 )
221238
222239 with pytest .raises (
@@ -340,7 +357,7 @@ async def test_decorator_auto_renewal_failure_propagation(
340357 monkeypatch : pytest .MonkeyPatch ,
341358):
342359 """Test that auto-renewal failures properly propagate as exceptions in the decorator"""
343- from servicelib .redis ._semaphore import renew_semaphore_entry
360+ from servicelib .redis ._semaphore import _renew_semaphore_entry
344361
345362 class RenewalFailureError (Exception ):
346363 """Custom exception for testing renewal failures"""
@@ -349,7 +366,7 @@ class RenewalFailureError(Exception):
349366
350367 # Mock the renewal function to fail after first call
351368 call_count = 0
352- original_renew = renew_semaphore_entry
369+ original_renew = _renew_semaphore_entry
353370
354371 async def failing_renew_semaphore_entry (semaphore ):
355372 nonlocal call_count
@@ -362,7 +379,7 @@ async def failing_renew_semaphore_entry(semaphore):
362379 raise RenewalFailureError ("Simulated renewal failure" )
363380
364381 monkeypatch .setattr (
365- "servicelib.redis._semaphore.renew_semaphore_entry " ,
382+ "servicelib.redis._semaphore._renew_semaphore_entry " ,
366383 failing_renew_semaphore_entry ,
367384 )
368385
@@ -646,16 +663,16 @@ class UserFunctionError(Exception):
646663
647664 # Track that auto-renewal is actually happening
648665 original_renew = __import__ (
649- "servicelib.redis._semaphore" , fromlist = ["renew_semaphore_entry " ]
650- ).renew_semaphore_entry
666+ "servicelib.redis._semaphore" , fromlist = ["_renew_semaphore_entry " ]
667+ )._renew_semaphore_entry
651668
652669 async def tracking_renew_semaphore_entry (semaphore ):
653670 nonlocal renewal_count
654671 renewal_count += 1
655672 await original_renew (semaphore )
656673
657674 with mock .patch (
658- "servicelib.redis._semaphore.renew_semaphore_entry " ,
675+ "servicelib.redis._semaphore._renew_semaphore_entry " ,
659676 side_effect = tracking_renew_semaphore_entry ,
660677 ):
661678
0 commit comments