@@ -199,26 +199,48 @@ async def test_CapacityLimiter_zero_limit_tokens() -> None:
199199 async with _core .open_nursery () as nursery :
200200 c .total_tokens = 0
201201
202- for i in range (6 ):
202+ for i in range (5 ):
203203 nursery .start_soon (c .acquire_on_behalf_of , i )
204204 await wait_all_tasks_blocked ()
205205
206206 assert set (c .statistics ().borrowers ) == set ()
207+ assert c .statistics ().tasks_waiting == 5
207208
208209 c .total_tokens = 5
209210
210211 assert set (c .statistics ().borrowers ) == {0 , 1 , 2 , 3 , 4 }
211212
212- for i in range (6 ):
213+ nursery .start_soon (c .acquire_on_behalf_of , 5 )
214+ await wait_all_tasks_blocked ()
215+
216+ assert c .statistics ().tasks_waiting == 1
217+
218+ for i in range (5 ):
213219 c .release_on_behalf_of (i )
214220
221+ assert c .statistics ().tasks_waiting == 0
222+ c .release_on_behalf_of (5 )
223+
215224 # making sure that zero limit capacity limiter doesn't let any tasks through
216225
217226 c .total_tokens = 0
218227
219228 with pytest .raises (_core .WouldBlock ):
220229 c .acquire_nowait ()
221230
231+ nursery .start_soon (c .acquire_on_behalf_of , 6 )
232+ await wait_all_tasks_blocked ()
233+
234+ assert c .statistics ().tasks_waiting == 1
235+ assert c .statistics ().borrowers == []
236+
237+ c .total_tokens = 1
238+ assert c .statistics ().tasks_waiting == 0
239+ assert c .statistics ().borrowers == [6 ]
240+
241+ c .release_on_behalf_of (6 )
242+ c .total_tokens = 0
243+
222244 nursery .cancel_scope .cancel ()
223245
224246 assert c .total_tokens == 0
0 commit comments