@@ -136,6 +136,7 @@ async def test_func(*args, **kwargs):
136136
137137 await test_func (2 )
138138
139+
139140@pytest .mark .asyncio
140141async def test_custom_callable_as_bucket ():
141142 def first_arg (* args ):
@@ -152,6 +153,7 @@ async def test_func(*args, **kwargs):
152153
153154 await test_func (2 )
154155
156+
155157@pytest .mark .asyncio
156158async def test_async_custom_callable_as_bucket ():
157159 async def first_arg (* args ):
@@ -168,6 +170,7 @@ async def test_func(*args, **kwargs):
168170
169171 await test_func (2 )
170172
173+
171174@pytest .mark .asyncio
172175async def test_async_bucket_process ():
173176 class CustomBucket (Enum ):
@@ -392,3 +395,33 @@ async def test():
392395 assert _cooldown .get_cooldown_times_per (await _cooldown .get_bucket ()) is None
393396 await test ()
394397 assert _cooldown .get_cooldown_times_per (await _cooldown .get_bucket ()) is not None
398+
399+
400+ @pytest .mark .asyncio
401+ async def test_inline_cooldowns ():
402+ # Can be called once every second
403+ # Default bucket is ALL arguments
404+ @cooldown (1 , 1 , bucket = CooldownBucket .all )
405+ async def test_func (* args , ** kwargs ) -> (tuple , dict ):
406+ return args , kwargs
407+
408+ _cooldown : Cooldown = getattr (test_func , "_cooldowns" )[0 ]
409+ # Call it once, so its on cooldown after this
410+ data = await test_func (1 , two = 2 )
411+ assert data == ((1 ,), {"two" : 2 })
412+
413+ with pytest .raises (CallableOnCooldown ):
414+ # Since this uses the same arguments
415+ # as the previous call, it comes under
416+ # the same bucket, and thus gets rate-limited
417+ await _cooldown .increment (1 , two = 2 )
418+
419+ # Shouldn't error as it comes under the
420+ # bucket _HashableArguments(1) rather then
421+ # the bucket _HashableArguments(1, two=2)
422+ # which are completely different
423+ await test_func (1 )
424+
425+ await _cooldown .increment (1 , two = 3 )
426+ with pytest .raises (CallableOnCooldown ):
427+ await _cooldown .increment (1 , two = 3 )
0 commit comments