summaryrefslogtreecommitdiff
path: root/test/engine/test_reconnect.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-02-09 15:06:32 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2011-02-09 15:06:32 -0500
commit6f16b8db6f08cefd68cdf251292316497eb849b3 (patch)
treedd86ad7eb16671bfec3ea091f2b0cfd5b6e18893 /test/engine/test_reconnect.py
parentf473398f0170a00b0e760a7dba292087144c7e45 (diff)
downloadsqlalchemy-6f16b8db6f08cefd68cdf251292316497eb849b3.tar.gz
- add connection and cursor to is_disconnect(). We aren't using it yet,
but we'd like to. Most DBAPIs don't give us anything we can do with it. Some research was done on psycopg2 and it still seems like they give us no adequate method (tried connection.closed, cursor.closed, connection.status). mxodbc claims their .closed attribute will work (but I am skeptical). - remove beahvior in pool that auto-invalidated a connection when the cursor failed to create. That's not the pool's job. we need the conn for the error logic. Can't get any tests to fail, curious why that behavior was there, guess we'll find out (or not). - add support for psycopg2 version detection. even though we have no use for it yet... - adjust one of the reconnect tests to work with oracle's horrendously slow connect speed
Diffstat (limited to 'test/engine/test_reconnect.py')
-rw-r--r--test/engine/test_reconnect.py39
1 files changed, 35 insertions, 4 deletions
diff --git a/test/engine/test_reconnect.py b/test/engine/test_reconnect.py
index 31a2b705a..9b3a1b4db 100644
--- a/test/engine/test_reconnect.py
+++ b/test/engine/test_reconnect.py
@@ -58,7 +58,7 @@ class MockReconnectTest(TestBase):
module=dbapi, _initialize=False)
# monkeypatch disconnect checker
- db.dialect.is_disconnect = lambda e: isinstance(e, MockDisconnect)
+ db.dialect.is_disconnect = lambda e, conn, cursor: isinstance(e, MockDisconnect)
def test_reconnect(self):
"""test that an 'is_disconnect' condition will invalidate the
@@ -259,6 +259,22 @@ class RealReconnectTest(TestBase):
conn.close()
+ def test_ensure_is_disconnect_gets_connection(self):
+ def is_disconnect(e, conn, cursor):
+ # connection is still present
+ assert conn.connection is not None
+ # the error usually occurs on connection.cursor(),
+ # though MySQLdb we get a non-working cursor.
+ # assert cursor is None
+
+ engine.dialect.is_disconnect = is_disconnect
+ conn = engine.connect()
+ engine.test_shutdown()
+ assert_raises(
+ tsa.exc.DBAPIError,
+ conn.execute, select([1])
+ )
+
def test_invalidate_twice(self):
conn = engine.connect()
conn.invalidate()
@@ -280,7 +296,7 @@ class RealReconnectTest(TestBase):
p1 = engine.pool
- def is_disconnect(e):
+ def is_disconnect(e, conn, cursor):
return True
engine.dialect.is_disconnect = is_disconnect
@@ -374,13 +390,28 @@ class RecycleTest(TestBase):
def test_basic(self):
for threadlocal in False, True:
- engine = engines.reconnecting_engine(options={'pool_recycle'
- : 1, 'pool_threadlocal': threadlocal})
+ engine = engines.reconnecting_engine(
+ options={'pool_threadlocal': threadlocal})
+
conn = engine.contextual_connect()
eq_(conn.execute(select([1])).scalar(), 1)
conn.close()
+
+ # set the pool recycle down to 1.
+ # we aren't doing this inline with the
+ # engine create since cx_oracle takes way
+ # too long to create the 1st connection and don't
+ # want to build a huge delay into this test.
+
+ engine.pool._recycle = 1
+
+ # kill the DB connection
engine.test_shutdown()
+
+ # wait until past the recycle period
time.sleep(2)
+
+ # can connect, no exception
conn = engine.contextual_connect()
eq_(conn.execute(select([1])).scalar(), 1)
conn.close()