]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
py2.4 seems to have different memory behavior than 2.5, test for both "adjusting...
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 10 May 2008 19:27:05 +0000 (19:27 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 10 May 2008 19:27:05 +0000 (19:27 +0000)
test/orm/memusage.py

index f9c645c8b3e5f9c3ab9b94ccff5e873206d92d1d..845b19017801950f3614dd6fb29bc30c58f9a341 100644 (file)
@@ -26,14 +26,20 @@ def profile_memory(func):
         print "sample gc sizes:", samples
 
         assert len(_sessions) == 0
-
-        # TODO: this test only finds pure "growing" tests.
-        # if a drop is detected, it's assumed that GC is able
-        # to reduce memory.  better methodology would
-        # make this more accurate.
+        
+        # look in the last 20 entries.  we look for one of two patterns: 
+        # either "flatline", i.e. 103240, 103240, 103240, 103240, ....
+        # or "adjusting down", i.e. 103240, 103248, 103256, 103104, 103112, ....
+        
         for i in range(len(samples) - 20, len(samples)):
-            if samples[i] > samples[i-1]:
-                assert False, repr(samples) +  " %d > %d"  % (samples[i], samples[i-1])
+            # adjusting down
+            if samples[i] < samples[i-1]:
+                break
+        else:
+            # no adjusting down.  check for "flatline"
+            for i in range(len(samples) - 20, len(samples)):
+                if samples[i] > samples[i-1]:
+                    assert False, repr(samples) +  " %d > %d"  % (samples[i], samples[i-1])
     return profile
 
 def assert_no_mappers():
@@ -48,6 +54,7 @@ class EnsureZeroed(_base.ORMTest):
 
 class MemUsageTest(EnsureZeroed):
     
+    # ensure a pure growing test trips the assertion
     @testing.fails_if(lambda:True)
     def test_fixture(self):
         class Foo(object):