]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Migrated gc.collect hack to testlib.compat
authorJason Kirtland <jek@discorporate.us>
Wed, 1 Apr 2009 01:52:16 +0000 (01:52 +0000)
committerJason Kirtland <jek@discorporate.us>
Wed, 1 Apr 2009 01:52:16 +0000 (01:52 +0000)
19 files changed:
test/engine/pool.py
test/engine/reconnect.py
test/ext/associationproxy.py
test/orm/attributes.py
test/orm/expire.py
test/orm/session.py
test/orm/transaction.py
test/perf/masscreate.py
test/perf/masscreate2.py
test/perf/massload.py
test/perf/masssave.py
test/perf/objselectspeed.py
test/perf/objupdatespeed.py
test/perf/sessions.py
test/profiling/memusage.py
test/testlib/__init__.py
test/testlib/compat.py
test/testlib/profiling.py
test/testlib/sa_gc.py [deleted file]

index 33ef80ff8f1ed5c0b12f0a9609a9614271d95cbb..93c6fe8dd0bb91eecdbb0be2f1f603dd3ba899f4 100644 (file)
@@ -2,7 +2,8 @@ import testenv; testenv.configure_for_tests()
 import threading, time
 from sqlalchemy import pool, interfaces, create_engine
 import testlib.sa as tsa
-from testlib import TestBase, gc, testing
+from testlib import TestBase, testing
+from testlib.compat import gc_collect
 
 
 mcid = 1
@@ -542,7 +543,7 @@ class QueuePoolTest(PoolTestBase):
        c2 = None
        del c1
        del c2
-       gc.collect()
+       gc_collect()
        assert p.checkedout() == 0
        c3 = p.connect()
        assert c3 is not None
index e1d5744db52e30482764b79997c7b0758ad8def5..1203a152b7e09962f0497859135431d0dee089d0 100644 (file)
@@ -1,9 +1,11 @@
 import testenv; testenv.configure_for_tests()
+import time
 import weakref
 from testlib.sa import select, MetaData, Table, Column, Integer, String, pool
 import testlib.sa as tsa
-from testlib import TestBase, testing, engines, gc
-import time
+from testlib import TestBase, testing, engines
+from testlib.compat import gc_collect
+
 
 class MockDisconnect(Exception):
     pass
@@ -95,7 +97,7 @@ class MockReconnectTest(TestBase):
         assert id(db.pool) != pid
 
         # ensure all connections closed (pool was recycled)
-        gc.collect()
+        gc_collect()
         assert len(dbapi.connections) == 0
 
         conn =db.connect()
@@ -115,7 +117,7 @@ class MockReconnectTest(TestBase):
             pass
 
         # assert was invalidated
-        gc.collect()
+        gc_collect()
         assert len(dbapi.connections) == 0
         assert not conn.closed
         assert conn.invalidated
@@ -165,7 +167,7 @@ class MockReconnectTest(TestBase):
         assert conn.invalidated
 
         # ensure all connections closed (pool was recycled)
-        gc.collect()
+        gc_collect()
         assert len(dbapi.connections) == 0
 
         # test reconnects
index 64683819bc5154fbcefab35c78099bb602751ea0..8b2d9e5548c056f29cee358b7315eb41f081f18b 100644 (file)
@@ -4,6 +4,7 @@ from sqlalchemy.orm import *
 from sqlalchemy.orm.collections import collection
 from sqlalchemy.ext.associationproxy import *
 from testlib import *
+from testlib.compat import gc_collect
 
 
 class DictCollection(dict):
@@ -864,7 +865,7 @@ class ReconstitutionTest(TestBase):
 
 
         add_child('p1', 'c1')
-        gc.collect()
+        gc_collect()
         add_child('p1', 'c2')
 
         session.flush()
@@ -877,7 +878,7 @@ class ReconstitutionTest(TestBase):
         p.kids.extend(['c1', 'c2'])
         p_copy = copy.copy(p)
         del p
-        gc.collect()
+        gc_collect()
 
         assert set(p_copy.kids) == set(['c1', 'c2']), p.kids
 
index be8cbf714cf0f59f473fff4568075a9de4f19234..46d944cbc3a4c2e1a42ed93bdd0e33d8d0d7dcf5 100644 (file)
@@ -5,6 +5,7 @@ from sqlalchemy.orm.collections import collection
 from sqlalchemy.orm.interfaces import AttributeExtension
 from sqlalchemy import exc as sa_exc
 from testlib import *
+from testlib.compat import gc_collect
 from testlib.testing import eq_
 from orm import _base
 
@@ -115,7 +116,7 @@ class AttributesTest(_base.ORMTest):
         f.bar = "foo"
         assert state.dict == {'bar':'foo', state.manager.STATE_ATTR:state}
         del f
-        gc.collect()
+        gc_collect()
         assert state.obj() is None
         assert state.dict == {}
         
index bbc011f875aee28b87d2f645b238f2a1617cc74a..34e9a57fe37957af346687ce36d657c79ffeff07 100644 (file)
@@ -1,7 +1,8 @@
 """Attribute/instance expiration, deferral of attributes, etc."""
 
 import testenv; testenv.configure_for_tests()
-from testlib import gc, sa, testing
+from testlib import sa, testing
+from testlib.compat import gc_collect
 from testlib.sa import Table, Column, Integer, String, ForeignKey, exc as sa_exc
 from testlib.sa.orm import mapper, relation, create_session, attributes, deferred
 from orm import _base, _fixtures
@@ -662,7 +663,7 @@ class ExpireTest(_fixtures.FixtureTest):
         assert self.static.user_address_result == userlist
         assert len(list(sess)) == 9
         sess.expire_all()
-        gc.collect()
+        gc_collect()
         assert len(list(sess)) == 4 # since addresses were gc'ed
 
         userlist = sess.query(User).order_by(User.id).all()
index dc5bf257844b66ec0eaabf866b688b4da0258160..5a2229b16c42b50f802ffda493aee5b01ff7a983 100644 (file)
@@ -2,7 +2,8 @@ import testenv; testenv.configure_for_tests()
 import inspect
 import pickle
 from sqlalchemy.orm import create_session, sessionmaker, attributes
-from testlib import engines, gc, sa, testing, config
+from testlib import engines, sa, testing, config
+from testlib.compat import gc_collect
 from testlib.sa import Table, Column, Integer, String, Sequence
 from testlib.sa.orm import mapper, relation, backref
 from testlib.testing import eq_
@@ -225,7 +226,7 @@ class SessionTest(_fixtures.FixtureTest):
         u = sess.query(User).get(u.id)
         q = sess.query(Address).filter(Address.user==u)
         del u
-        gc.collect()
+        gc_collect()
         eq_(q.one(), Address(email_address='foo'))
 
 
@@ -757,18 +758,18 @@ class SessionTest(_fixtures.FixtureTest):
 
         user = s.query(User).one()
         del user
-        gc.collect()
+        gc_collect()
         assert len(s.identity_map) == 0
 
         user = s.query(User).one()
         user.name = 'fred'
         del user
-        gc.collect()
+        gc_collect()
         assert len(s.identity_map) == 1
         assert len(s.dirty) == 1
         assert None not in s.dirty
         s.flush()
-        gc.collect()
+        gc_collect()
         assert not s.dirty
         assert not s.identity_map
 
@@ -787,7 +788,7 @@ class SessionTest(_fixtures.FixtureTest):
         user = s.query(User).one()
         user = None
         print s.identity_map
-        gc.collect()
+        gc_collect()
         assert len(s.identity_map) == 1
 
         user = s.query(User).one()
@@ -810,7 +811,7 @@ class SessionTest(_fixtures.FixtureTest):
         self.assert_(len(s.identity_map) == 0)
         self.assert_(s.prune() == 0)
         s.flush()
-        gc.collect()
+        gc_collect()
         self.assert_(s.prune() == 9)
         self.assert_(len(s.identity_map) == 1)
 
index 444a851dd198d9a1b68ea8b7e9a7c1e0b7783a78..c845c379f0d653255ed2b012d949ad46bdb898ab 100644 (file)
@@ -5,8 +5,10 @@ from sqlalchemy.orm import attributes
 from sqlalchemy import exc as sa_exc
 from sqlalchemy.orm import *
 from testlib import *
+from testlib.compat import gc_collect
 from testlib.fixtures import *
 
+
 class TransactionTest(FixtureTest):
     keep_mappers = True
     session = sessionmaker()
@@ -104,7 +106,7 @@ class AutoExpireTest(TransactionTest):
         assert u1_state not in s.identity_map.all_states()
         assert u1_state not in s._deleted
         del u1
-        gc.collect()
+        gc_collect()
         assert u1_state.obj() is None
         
         s.rollback()
index 10f6514f0e3cee9b7a3b4b4bd8f633b37698cb36..5b8e0da555adb9f5b6ceeab457d3408ac53cbada 100644 (file)
@@ -2,7 +2,6 @@
 import testenv; testenv.simple_setup()
 
 from sqlalchemy.orm import attributes
-from testlib import gc
 import time
 
 manage_attributes = True
@@ -34,7 +33,6 @@ for i in range(0,130):
             attributes.manage(a)
         a.email = 'foo@bar.com'
         u.addresses.append(a)
-#    gc.collect()
 #    print len(managed_attributes)
 #    managed_attributes.clear()
 total = time.time() - now
index 88a4d3c17ec1a73bf9f1e8c162147ab6be4344fb..cedd67e177b68006bfbbb8b9eeefca30f3c0ccc3 100644 (file)
@@ -3,7 +3,7 @@ import testenv; testenv.simple_setup()
 import random, string
 
 from sqlalchemy.orm import attributes
-from testlib import gc
+from testlib.compat import gc_collect
 
 # with this test, run top.  make sure the Python process doenst grow in size arbitrarily.
 
@@ -33,4 +33,4 @@ for i in xrange(1000):
       a.user = u
   print "clearing"
   #managed_attributes.clear()
-  gc.collect()
+  gc_collect()
index 4e2b05d123b3b3acea27ebe029cc3c12949d6d11..ecc45e2b913b222ee825e019ee8697c23823e7fb 100644 (file)
@@ -42,7 +42,7 @@ class LoadTest(TestBase, AssertsExecutionResults):
         query = sess.query(Item)
         for x in range (1,NUM/100):
             # this is not needed with cpython which clears non-circular refs immediately
-            #gc.collect()
+            #gc_collect()
             l = query.filter(items.c.item_id.between(x*100 - 100 + 1, x*100)).all()
             assert len(l) == 100
             print "loaded ", len(l), " items "
index bf65c8fdf70024a66141087c9714d36021dc5838..5dc0f199657697a9ad6f49894dccf1753a263a8f 100644 (file)
@@ -1,4 +1,5 @@
 import testenv; testenv.configure_for_tests()
+import gc
 import types
 from sqlalchemy import *
 from sqlalchemy.orm import *
index 788bdcd46b3044c18eb03f62a1cf9772bd8e45bd..0c2c6084dd16cc86b497d54e78e36ae14d4122c2 100644 (file)
@@ -2,7 +2,7 @@ import testenv; testenv.simple_setup()
 import time, resource
 from sqlalchemy import *
 from sqlalchemy.orm import *
-from testlib import gc
+from testlib.compat import gc_collect
 
 
 db = create_engine('sqlite://')
@@ -69,35 +69,35 @@ def all():
         usage.snap = lambda stats=None: setattr(
             usage, 'last', stats or resource.getrusage(resource.RUSAGE_SELF))
 
-        gc.collect()
+        gc_collect()
         usage.snap()
         t = time.clock()
         sqlite_select(RawPerson)
         t2 = time.clock()
         usage('sqlite select/native')
 
-        gc.collect()
+        gc_collect()
         usage.snap()
         t = time.clock()
         sqlite_select(Person)
         t2 = time.clock()
         usage('sqlite select/instrumented')
 
-        gc.collect()
+        gc_collect()
         usage.snap()
         t = time.clock()
         sql_select(RawPerson)
         t2 = time.clock()
         usage('sqlalchemy.sql select/native')
 
-        gc.collect()
+        gc_collect()
         usage.snap()
         t = time.clock()
         sql_select(Person)
         t2 = time.clock()
         usage('sqlalchemy.sql select/instrumented')
 
-        gc.collect()
+        gc_collect()
         usage.snap()
         t = time.clock()
         orm_select()
index a6ed83a07df89775c8ce75cd452dad2c317d572d..785766f8bf792de867e80f7f4fd4be1556d56e49 100644 (file)
@@ -3,6 +3,8 @@ import time, resource
 from sqlalchemy import *
 from sqlalchemy.orm import *
 from testlib import *
+from testlib.compat import gc_collect
+
 
 NUM = 100
 
@@ -72,14 +74,14 @@ def all():
 
         session = create_session()
 
-        gc.collect()
+        gc_collect()
         usage.snap()
         t = time.clock()
         people = orm_select(session)
         t2 = time.clock()
         usage('load objects')
 
-        gc.collect()
+        gc_collect()
         usage.snap()
         t = time.clock()
         update_and_flush(session, people)
index 9d0e480f89193398680e9445cbbaf399757cf352..a9f948ec901f28d6caadaa5fae007c499b188b6a 100644 (file)
@@ -2,6 +2,7 @@ import testenv; testenv.configure_for_tests()
 from sqlalchemy import *
 from sqlalchemy.orm import *
 from testlib import *
+from testlib.compat import gc_collect
 from testlib import fixtures
 
 # in this test we are specifically looking for time spent in the attributes.InstanceState.__cleanup() method.
@@ -58,7 +59,7 @@ class SessionTest(TestBase, AssertsExecutionResults):
 
             sess.close()
             del sess
-            gc.collect()
+            gc_collect()
 
     @profiling.profiled('dirty', report=True)
     def test_session_dirty(self):
@@ -72,11 +73,11 @@ class SessionTest(TestBase, AssertsExecutionResults):
                     t2.c2 = 'this is some modified text'
 
             del t1s
-            gc.collect()
+            gc_collect()
             
             sess.close()
             del sess
-            gc.collect()
+            gc_collect()
 
     @profiling.profiled('noclose', report=True)
     def test_session_noclose(self):
@@ -87,8 +88,7 @@ class SessionTest(TestBase, AssertsExecutionResults):
                 t1s[index].t2s
 
             del sess
-            gc.collect()
-        
+            gc_collect()
 
 
 if __name__ == '__main__':
index fb5df227d670ed3abf25d0fc789f11fb8152c7cc..7b684f1a977c3c883b0f299e33e878f1b12b30a8 100644 (file)
@@ -2,8 +2,10 @@ import testenv; testenv.configure_for_tests()
 from sqlalchemy.orm import mapper, relation, create_session, clear_mappers, sessionmaker
 from sqlalchemy.orm.mapper import _mapper_registry
 from sqlalchemy.orm.session import _sessions
+import gc
 import operator
-from testlib import gc, testing
+from testlib import testing
+from testlib.compat import gc_collect
 from testlib.sa import MetaData, Table, Column, Integer, String, ForeignKey, PickleType
 import sqlalchemy as sa
 from sqlalchemy.sql import column
@@ -21,11 +23,11 @@ def profile_memory(func):
     # run the test 50 times.  if length of gc.get_objects()
     # keeps growing, assert false
     def profile(*args):
-        gc.collect()
+        gc_collect()
         samples = [0 for x in range(0, 50)]
         for x in range(0, 50):
             func(*args)
-            gc.collect()
+            gc_collect()
             samples[x] = len(gc.get_objects())
         print "sample gc sizes:", samples
 
@@ -49,7 +51,7 @@ def profile_memory(func):
 
 def assert_no_mappers():
     clear_mappers()
-    gc.collect()
+    gc_collect()
     assert len(_mapper_registry) == 0
 
 class EnsureZeroed(_base.ORMTest):
@@ -381,7 +383,7 @@ class MemUsageTest(EnsureZeroed):
             testing.eq_(len(session.identity_map._mutable_attrs), 12)
             testing.eq_(len(session.identity_map), 12)
             obj = None
-            gc.collect()
+            gc_collect()
             testing.eq_(len(session.identity_map._mutable_attrs), 0)
             testing.eq_(len(session.identity_map), 0)
             
index 3996364a070e53a439ca8ddbded0bbbe85fd29c3..5dea60322b953d65714b35c469b8f9361f0dfdcb 100644 (file)
@@ -17,7 +17,6 @@ from testlib.testing import \
 from testlib.orm import mapper
 import testlib.profiling as profiling
 import testlib.engines as engines
-import testlib.sa_gc as gc
 import testlib.requires as requires
 from testlib.compat import _function_named
 
@@ -28,7 +27,7 @@ __all__ = ('testing',
            'rowset',
            'TestBase', 'AssertsExecutionResults', 'ORMTest',
            'AssertsCompiledSQL', 'ComparesTables',
-           'profiling', 'engines', 'gc',
+           'profiling', 'engines',
            '_function_named')
 
 
index dd23560be856a3e282beb5802e6f30483d46cdb2..8f99527f93242960171b41d02ae79f73a407422d 100644 (file)
@@ -1,4 +1,9 @@
-import sys, types, __builtin__
+import gc
+import sys
+import time
+import types
+import __builtin__
+
 
 __all__ = '_function_named', 'callable', 'py3k', 'jython'
 
@@ -26,3 +31,12 @@ if py3k:
 else:
     callable = __builtin__.callable
 
+if sys.platform.startswith('java'):
+    def gc_collect(*args):
+        gc.collect()
+        time.sleep(0.1)
+        gc.collect()
+        gc.collect()
+        return 0
+else:
+    gc_collect = gc.collect
index 89db3301110d5c73d33967aadd95ecea7df6a298..41a47b00a35e83639b91315c17ea96fe68a47af2 100644 (file)
@@ -1,7 +1,7 @@
 """Profiling support for unit and performance tests."""
 
 import os, sys
-from testlib.compat import _function_named
+from testlib.compat import _function_named, gc_collect
 import testlib.config
 
 __all__ = 'profiled', 'function_call_count', 'conditional_call_count'
@@ -179,7 +179,7 @@ def _profile_cProfile(filename, fn, *args, **kw):
     import cProfile, gc, pstats, time
 
     load_stats = lambda: pstats.Stats(filename)
-    gc.collect()
+    gc_collect()
 
     began = time.time()
     cProfile.runctx('result = fn(*args, **kw)', globals(), locals(),
@@ -192,7 +192,7 @@ def _profile_hotshot(filename, fn, *args, **kw):
     import gc, hotshot, hotshot.stats, time
     load_stats = lambda: hotshot.stats.load(filename)
 
-    gc.collect()
+    gc_collect()
     prof = hotshot.Profile(filename)
     began = time.time()
     prof.start()
diff --git a/test/testlib/sa_gc.py b/test/testlib/sa_gc.py
deleted file mode 100644 (file)
index 6e18575..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-"""Cross platform garbage collection utility"""
-import gc
-import sys
-import time
-
-if sys.platform.startswith('java'):
-    def collect(*args):
-        gc.collect()
-        time.sleep(0.1)
-        gc.collect()
-        gc.collect()
-        return 0
-else:
-    collect = gc.collect