Пример #1
0
 def test_is_disconnection_error_with_ssl_syscall_error(self):
     """
     If the underlying driver raises a ProgrammingError with 'SSL SYSCALL
     error', we consider the connection dead and mark it as needing
     reconnection.
     """
     exc = ProgrammingError("SSL SYSCALL error: Connection timed out")
     self.assertTrue(self.connection.is_disconnection_error(exc))
Пример #2
0
 def begin(self, xid):
     """Begin a two-phase transaction."""
     if self._two_phase_transaction:
         raise ProgrammingError("begin cannot be used inside a transaction")
     self._ensure_connected()
     raw_xid = self._raw_xid(xid)
     self._check_disconnect(self._raw_connection.tpc_begin, raw_xid)
     self._two_phase_transaction = True
Пример #3
0
    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)
Пример #4
0
    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)
Пример #5
0
    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)
Пример #6
0
 def prepare(self):
     """Run the prepare phase of a two-phase transaction."""
     if not self._two_phase_transaction:
         raise ProgrammingError("prepare must be called inside a two-phase "
                                "transaction")
     self._check_disconnect(self._raw_connection.tpc_prepare)