File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ class ErrorRateExceeded(Exception):
136136def limit_error_rate (fails , timeout , exception = ErrorRateExceeded ):
137137 """If function fails to complete fails times in a row,
138138 calls to it will be intercepted for timeout with exception raised instead."""
139- if isinstance (timeout , int ):
139+ if isinstance (timeout , ( int , float ) ):
140140 timeout = timedelta (seconds = timeout )
141141
142142 def decorator (func ):
Original file line number Diff line number Diff line change @@ -308,3 +308,19 @@ def run():
308308 assert not worker .is_alive (), 'reentrant call deadlocked'
309309 assert not errors
310310 assert calls == expected
311+
312+
313+ @pytest .mark .parametrize ('timeout' , [0.5 , timedelta (seconds = 0.5 )])
314+ def test_limit_error_rate_fractional_timeout (timeout ):
315+ @limit_error_rate (1 , timeout )
316+ def fail ():
317+ raise MyError
318+
319+ with pytest .raises (MyError ):
320+ fail ()
321+ with pytest .raises (ErrorRateExceeded ):
322+ fail ()
323+
324+ fail .blocked -= timedelta (seconds = 1 )
325+ with pytest .raises (MyError ):
326+ fail ()
You can’t perform that action at this time.
0 commit comments