#NEWLINE# def test_backoff_with_jitter( self ) : #NEWLINE# #INDENT# self . breaker = breaker . CircuitBreaker ( self . clock . time , self . log , [ IOError ] , self . maxfail , self . reset_timeout , self . time_unit , 64 , with_jitter = True ) #NEWLINE# self . test_opens_breaker_on_errors ( ) #NEWLINE# self . clock . advance ( self . reset_timeout ) #NEWLINE# self . breaker . test ( ) #NEWLINE# self . breaker . error ( ) #NEWLINE# self . assertEquals ( self . breaker . test_fail_count , 1 ) #NEWLINE# self . clock . advance ( ( self . reset_timeout * 2 ) ) #NEWLINE# self . breaker . test ( ) #NEWLINE# self . breaker . error ( ) #NEWLINE# self . assertEquals ( self . breaker . test_fail_count , 2 ) #NEWLINE# failure_count = 0 #NEWLINE# self . clock . advance ( ( self . reset_timeout * 2 ) ) #NEWLINE# for _ in xrange ( 0 , 1000 ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . breaker . test ( ) #NEWLINE# self . breaker . open ( ) #NEWLINE# self . clock . advance ( ( self . reset_timeout * 2 ) ) #NEWLINE# #UNINDENT# except CircuitOpenError : #NEWLINE# #INDENT# failure_count += 1 #NEWLINE# #UNINDENT# #UNINDENT# self . assertGreater ( failure_count , 400 ) #NEWLINE# self . assertLess ( failure_count , 600 )