Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_breaker(self):
class MyBreaker(CircuitBreaker):
def run(self):
assert not getattr(self, 'fail', False)
breaker = MyBreaker(4, 600)
self.assertTrue(breaker.is_ready())
breaker()
self.assertFalse(breaker.failures)
breaker.open_circuit()
self.assertFalse(breaker.is_ready())
breaker.error_expiration = datetime.datetime.now()
breaker()
self.assertTrue(breaker.is_ready())
breaker.fail = True
for i in range(3):
try:
breaker()