Merge "Repair string-based disconnect filters for MySQL, DB2"
This commit is contained in:
commit
571433bfc4
@ -269,9 +269,8 @@ def _raise_operational_errors_directly_filter(operational_error,
|
|||||||
raise operational_error
|
raise operational_error
|
||||||
|
|
||||||
|
|
||||||
# For the db2, the error code is -30081 since the db2 is still not ready
|
@filters("mysql", sqla_exc.OperationalError, r".*\(.*(?:2002|2003|2006|2013)")
|
||||||
@filters("mysql", sqla_exc.OperationalError, r".*\((?:2002|2003|2006|2013)")
|
@filters("ibm_db_sa", sqla_exc.OperationalError, r".*(?:30081)")
|
||||||
@filters("ibm_db_sa", sqla_exc.OperationalError, r".*(?:-30081)")
|
|
||||||
def _is_db_connection_error(operational_error, match, engine_name,
|
def _is_db_connection_error(operational_error, match, engine_name,
|
||||||
is_disconnect):
|
is_disconnect):
|
||||||
"""Detect the exception as indicating a recoverable error on connect."""
|
"""Detect the exception as indicating a recoverable error on connect."""
|
||||||
|
@ -665,7 +665,9 @@ class IntegrationTest(test_base.DbTestCase):
|
|||||||
class TestDBDisconnected(TestsExceptionFilter):
|
class TestDBDisconnected(TestsExceptionFilter):
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def _fixture(self, dialect_name, exception, num_disconnects):
|
def _fixture(
|
||||||
|
self,
|
||||||
|
dialect_name, exception, num_disconnects, is_disconnect=True):
|
||||||
engine = self.engine
|
engine = self.engine
|
||||||
|
|
||||||
compat.engine_connect(engine, session._connect_ping_listener)
|
compat.engine_connect(engine, session._connect_ping_listener)
|
||||||
@ -686,12 +688,13 @@ class TestDBDisconnected(TestsExceptionFilter):
|
|||||||
fake_do_execute),
|
fake_do_execute),
|
||||||
mock.patch.object(engine.dialect,
|
mock.patch.object(engine.dialect,
|
||||||
"is_disconnect",
|
"is_disconnect",
|
||||||
mock.Mock(return_value=True))
|
mock.Mock(return_value=is_disconnect))
|
||||||
):
|
):
|
||||||
yield
|
yield
|
||||||
|
|
||||||
def _test_ping_listener_disconnected(self, dialect_name, exc_obj):
|
def _test_ping_listener_disconnected(
|
||||||
with self._fixture(dialect_name, exc_obj, 1):
|
self, dialect_name, exc_obj, is_disconnect=True):
|
||||||
|
with self._fixture(dialect_name, exc_obj, 1, is_disconnect):
|
||||||
conn = self.engine.connect()
|
conn = self.engine.connect()
|
||||||
with conn.begin():
|
with conn.begin():
|
||||||
self.assertEqual(conn.scalar(sqla.select([1])), 1)
|
self.assertEqual(conn.scalar(sqla.select([1])), 1)
|
||||||
@ -699,7 +702,7 @@ class TestDBDisconnected(TestsExceptionFilter):
|
|||||||
self.assertFalse(conn.invalidated)
|
self.assertFalse(conn.invalidated)
|
||||||
self.assertTrue(conn.in_transaction())
|
self.assertTrue(conn.in_transaction())
|
||||||
|
|
||||||
with self._fixture(dialect_name, exc_obj, 2):
|
with self._fixture(dialect_name, exc_obj, 2, is_disconnect):
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
exception.DBConnectionError,
|
exception.DBConnectionError,
|
||||||
self.engine.connect
|
self.engine.connect
|
||||||
@ -716,6 +719,17 @@ class TestDBDisconnected(TestsExceptionFilter):
|
|||||||
self.OperationalError('%d MySQL server has gone away' % code)
|
self.OperationalError('%d MySQL server has gone away' % code)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_mysql_ping_listener_disconnected_regex_only(self):
|
||||||
|
# intentionally set the is_disconnect flag to False
|
||||||
|
# in the "sqlalchemy" layer to make sure the regexp
|
||||||
|
# on _is_db_connection_error is catching
|
||||||
|
for code in [2002, 2003, 2006, 2013]:
|
||||||
|
self._test_ping_listener_disconnected(
|
||||||
|
"mysql",
|
||||||
|
self.OperationalError('%d MySQL server has gone away' % code),
|
||||||
|
is_disconnect=False
|
||||||
|
)
|
||||||
|
|
||||||
def test_db2_ping_listener_disconnected(self):
|
def test_db2_ping_listener_disconnected(self):
|
||||||
self._test_ping_listener_disconnected(
|
self._test_ping_listener_disconnected(
|
||||||
"ibm_db_sa",
|
"ibm_db_sa",
|
||||||
@ -723,6 +737,14 @@ class TestDBDisconnected(TestsExceptionFilter):
|
|||||||
'SQL30081N: DB2 Server connection is no longer active')
|
'SQL30081N: DB2 Server connection is no longer active')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_db2_ping_listener_disconnected_regex_only(self):
|
||||||
|
self._test_ping_listener_disconnected(
|
||||||
|
"ibm_db_sa",
|
||||||
|
self.OperationalError(
|
||||||
|
'SQL30081N: DB2 Server connection is no longer active'),
|
||||||
|
is_disconnect=False
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestDBConnectRetry(TestsExceptionFilter):
|
class TestDBConnectRetry(TestsExceptionFilter):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user