def test_storm_timeout(self): """Test storm TimeoutError.""" called = set() def handler(): """handler.""" called.add('called') with on_timeout(handler): raise TimeoutError("fake-message", "fake statement", 'args') self.assertTrue(called)
def test_retrylimit(self): """Test retry limit case.""" called = set() def handler(): """handler.""" called.add('called') with on_timeout(handler): raise RetryLimitReached("a msg", extra_info="orginal exception") self.assertTrue(called)
def test_pg_timeout(self): """Test ProgrammingError pg timeout.""" called = set() def handler(): """handler.""" called.add('called') with on_timeout(handler): raise ProgrammingError("timeout") self.assertTrue(called)
def test_no_timeout(self): """Test no timeout.""" called = set() def handler(): """handler.""" called.add('called') with on_timeout(handler): pass self.assertFalse(called)
def test_non_timeout_programming_error(self): """Test other errors propagate.""" failing = set() called = set() def handler(): """handler.""" called.add('called') try: with on_timeout(handler): raise ProgrammingError("err") except ProgrammingError: failing.add('failing') self.assertFalse(called) self.assertTrue(failing)
def test_raising_handler(self): """Raising in the timeout handler works as expected.""" raised = set() called = set() class HandlerExc(Exception): """Handler raised exception.""" pass def handler(): """handler.""" called.add('called') raise HandlerExc() try: with on_timeout(handler): raise ProgrammingError("timed out") except HandlerExc: raised.add('raised') self.assertTrue(called) self.assertTrue(raised)