Skip to content

Commit a693032

Browse files
committed
rename
1 parent 5679a47 commit a693032

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

packages/service-library/src/servicelib/redis/_semaphore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ async def current_count(self) -> int:
408408
self.redis_client.redis.scard(self.holders_set)
409409
)
410410

411-
async def size(self) -> int:
411+
async def available_tokens(self) -> int:
412412
"""Get the size of the semaphore (number of available tokens)"""
413413
await self._ensure_semaphore_initialized()
414414
return await handle_redis_returns_union_types(

packages/service-library/tests/redis/test_semaphore.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ async def test_semaphore_acquire_release_basic(
145145

146146
# Initially not acquired
147147
assert await semaphore.current_count() == 0
148-
assert await semaphore.size() == semaphore_capacity
148+
assert await semaphore.available_tokens() == semaphore_capacity
149149
assert await semaphore.is_acquired() is False
150150
await _assert_semaphore_redis_state(
151151
redis_client_sdk,
@@ -158,7 +158,7 @@ async def test_semaphore_acquire_release_basic(
158158
result = await semaphore.acquire()
159159
assert result is True
160160
assert await semaphore.current_count() == 1
161-
assert await semaphore.size() == semaphore_capacity - 1
161+
assert await semaphore.available_tokens() == semaphore_capacity - 1
162162
assert await semaphore.is_acquired() is True
163163
await _assert_semaphore_redis_state(
164164
redis_client_sdk,
@@ -171,7 +171,7 @@ async def test_semaphore_acquire_release_basic(
171171
result = await semaphore.acquire()
172172
assert result is True
173173
assert await semaphore.current_count() == 1
174-
assert await semaphore.size() == semaphore_capacity - 1
174+
assert await semaphore.available_tokens() == semaphore_capacity - 1
175175
assert await semaphore.is_acquired() is True
176176
await _assert_semaphore_redis_state(
177177
redis_client_sdk,
@@ -183,7 +183,7 @@ async def test_semaphore_acquire_release_basic(
183183
# reacquire should just work
184184
await semaphore.reacquire()
185185
assert await semaphore.current_count() == 1
186-
assert await semaphore.size() == semaphore_capacity - 1
186+
assert await semaphore.available_tokens() == semaphore_capacity - 1
187187
assert await semaphore.is_acquired() is True
188188
await _assert_semaphore_redis_state(
189189
redis_client_sdk,
@@ -195,7 +195,7 @@ async def test_semaphore_acquire_release_basic(
195195
# Release
196196
await semaphore.release()
197197
assert await semaphore.current_count() == 0
198-
assert await semaphore.size() == semaphore_capacity
198+
assert await semaphore.available_tokens() == semaphore_capacity
199199
assert await semaphore.is_acquired() is False
200200
await _assert_semaphore_redis_state(
201201
redis_client_sdk,
@@ -239,7 +239,7 @@ async def test_semaphore_acquire_release_with_ttl_expiry(
239239
)
240240
await semaphore.acquire()
241241
assert await semaphore.current_count() == 1
242-
assert await semaphore.size() == semaphore_capacity - 1
242+
assert await semaphore.available_tokens() == semaphore_capacity - 1
243243
await _assert_semaphore_redis_state(
244244
redis_client_sdk,
245245
semaphore,
@@ -312,14 +312,14 @@ async def test_semaphore_multiple_instances_capacity_limit(
312312
assert await semaphores[1].is_acquired() is False
313313
for sem in semaphores[:4]:
314314
assert await sem.current_count() == 1
315-
assert await sem.size() == capacity - 1
315+
assert await sem.available_tokens() == capacity - 1
316316

317317
# acquire second
318318
assert await semaphores[1].acquire() is True
319319
for sem in semaphores[:2]:
320320
assert await sem.is_acquired() is True
321321
assert await sem.current_count() == 2
322-
assert await sem.size() == capacity - 2
322+
assert await sem.available_tokens() == capacity - 2
323323
await _assert_semaphore_redis_state(
324324
redis_client_sdk,
325325
sem,
@@ -333,20 +333,20 @@ async def test_semaphore_multiple_instances_capacity_limit(
333333
assert await sem.acquire() is False
334334
assert await sem.is_acquired() is False
335335
assert await sem.current_count() == 2
336-
assert await sem.size() == capacity - 2
336+
assert await sem.available_tokens() == capacity - 2
337337

338338
# Release one
339339
await semaphores[0].release()
340340
assert await semaphores[0].is_acquired() is False
341341
for sem in semaphores[:4]:
342342
assert await sem.current_count() == 1
343-
assert await sem.size() == capacity - 1
343+
assert await sem.available_tokens() == capacity - 1
344344

345345
# Now third can acquire
346346
assert await semaphores[2].acquire() is True
347347
for sem in semaphores[:4]:
348348
assert await sem.current_count() == 2
349-
assert await sem.size() == capacity - 2
349+
assert await sem.available_tokens() == capacity - 2
350350

351351
# Clean up
352352
await semaphores[1].release()
@@ -368,7 +368,7 @@ async def test_semaphore_context_manager(
368368
) as semaphore1:
369369
assert await semaphore1.is_acquired() is True
370370
assert await semaphore1.current_count() == 1
371-
assert await semaphore1.size() == 0
371+
assert await semaphore1.available_tokens() == 0
372372
await _assert_semaphore_redis_state(
373373
redis_client_sdk,
374374
semaphore1,

packages/service-library/tests/redis/test_semaphore_decorator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ async def long_running_work() -> Literal["success"]:
9393
ttl=short_ttl,
9494
)
9595
assert await temp_semaphore.current_count() == 1
96-
assert await temp_semaphore.size() == semaphore_capacity - 1
96+
assert await temp_semaphore.available_tokens() == semaphore_capacity - 1
9797

9898
# Wait for work to complete
9999
result = await task
@@ -102,7 +102,7 @@ async def long_running_work() -> Literal["success"]:
102102

103103
# After completion, semaphore should be released
104104
assert await temp_semaphore.current_count() == 0
105-
assert await temp_semaphore.size() == semaphore_capacity
105+
assert await temp_semaphore.available_tokens() == semaphore_capacity
106106

107107

108108
async def test_auto_renewal_lose_semaphore_raises(
@@ -606,15 +606,15 @@ async def use_long_running_cm():
606606
ttl=short_ttl,
607607
)
608608
assert await temp_semaphore.current_count() == 1
609-
assert await temp_semaphore.size() == semaphore_capacity - 1
609+
assert await temp_semaphore.available_tokens() == semaphore_capacity - 1
610610

611611
# Wait for work to complete
612612
await task
613613
assert work_completed.is_set()
614614

615615
# After completion, semaphore should be released
616616
assert await temp_semaphore.current_count() == 0
617-
assert await temp_semaphore.size() == semaphore_capacity
617+
assert await temp_semaphore.available_tokens() == semaphore_capacity
618618

619619

620620
async def test_context_manager_with_callable_parameters(

0 commit comments

Comments
 (0)