]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- dont use id() to test identity as these can be recycled
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 15 Jun 2016 22:15:46 +0000 (18:15 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 15 Jun 2016 22:15:46 +0000 (18:15 -0400)
Change-Id: Ie4cb4924909d55c5962f66e36cd5325e8e8f0538

test/engine/test_pool.py

index a4f891b3c62fa783f1ee1ea595666d29df85b08c..057289199f3ad9580ff0888fbe2d4f38b6108819 100644 (file)
@@ -1455,16 +1455,17 @@ class QueuePoolTest(PoolTestBase):
                 max_overflow=0,
                 recycle=30)
             c1 = p.connect()
-            c_id = id(c1.connection)
+            c_ref = weakref.ref(c1.connection)
             c1.close()
             mock.return_value = 10001
             c2 = p.connect()
-            assert id(c2.connection) == c_id
+
+            is_(c2.connection, c_ref())
             c2.close()
 
             mock.return_value = 10035
             c3 = p.connect()
-            assert id(c3.connection) != c_id
+            is_not_(c3.connection, c_ref())
 
     @testing.requires.timing_intensive
     def test_recycle_on_invalidate(self):
@@ -1472,10 +1473,10 @@ class QueuePoolTest(PoolTestBase):
             pool_size=1,
             max_overflow=0)
         c1 = p.connect()
-        c_id = id(c1.connection)
+        c_ref = weakref.ref(c1.connection)
         c1.close()
         c2 = p.connect()
-        assert id(c2.connection) == c_id
+        is_(c2.connection, c_ref())
 
         c2_rec = c2._connection_record
         p._invalidate(c2)
@@ -1483,7 +1484,8 @@ class QueuePoolTest(PoolTestBase):
         c2.close()
         time.sleep(.5)
         c3 = p.connect()
-        assert id(c3.connection) != c_id
+
+        is_not_(c3.connection, c_ref())
 
     @testing.requires.timing_intensive
     def test_recycle_on_soft_invalidate(self):
@@ -1491,21 +1493,21 @@ class QueuePoolTest(PoolTestBase):
             pool_size=1,
             max_overflow=0)
         c1 = p.connect()
-        c_id = id(c1.connection)
+        c_ref = weakref.ref(c1.connection)
         c1.close()
         c2 = p.connect()
-        assert id(c2.connection) == c_id
+        is_(c2.connection, c_ref())
 
         c2_rec = c2._connection_record
         c2.invalidate(soft=True)
-        assert c2_rec.connection is c2.connection
+        is_(c2_rec.connection, c2.connection)
 
         c2.close()
         time.sleep(.5)
         c3 = p.connect()
-        assert id(c3.connection) != c_id
-        assert c3._connection_record is c2_rec
-        assert c2_rec.connection is c3.connection
+        is_not_(c3.connection, c_ref())
+        is_(c3._connection_record, c2_rec)
+        is_(c2_rec.connection, c3.connection)
 
     def _no_wr_finalize(self):
         finalize_fairy = pool._finalize_fairy