diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-05-30 20:24:08 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-05-30 20:24:08 -0400 |
| commit | 9bab63b69341bf9d89a30de2f624644b55afc6e9 (patch) | |
| tree | b1c0a4956a743ba208a0c2cf506b9fcc634ac82d /test/aaa_profiling/test_memusage.py | |
| parent | a19e403010804ad25260a96e5f38e0894c1d72af (diff) | |
| download | sqlalchemy-9bab63b69341bf9d89a30de2f624644b55afc6e9.tar.gz | |
- Pool classes will reuse the same "pool_logging_name" setting
after a dispose() occurs.
- Engine gains an "execution_options" argument and
update_execution_options() method, which will apply to
all connections generated by this engine.
- Added more aggressive caching to the mapper's usage of
UPDATE, INSERT, and DELETE expressions. Assuming the
statement has no per-object SQL expressions attached,
the expression objects are cached by the mapper after
the first create, and their compiled form is stored
persistently in a cache dictionary for the duration of
the related Engine.
- change #3 required change #1 so that we could test
a set of mappers operating over the course of many engines without
memory usage increase.
Diffstat (limited to 'test/aaa_profiling/test_memusage.py')
| -rw-r--r-- | test/aaa_profiling/test_memusage.py | 68 |
1 files changed, 65 insertions, 3 deletions
diff --git a/test/aaa_profiling/test_memusage.py b/test/aaa_profiling/test_memusage.py index 711b03a02..2d64cd804 100644 --- a/test/aaa_profiling/test_memusage.py +++ b/test/aaa_profiling/test_memusage.py @@ -1,16 +1,18 @@ from sqlalchemy.test.testing import eq_ -from sqlalchemy.orm import mapper, relationship, create_session, clear_mappers, sessionmaker +from sqlalchemy.orm import mapper, relationship, create_session, clear_mappers, \ + sessionmaker, class_mapper from sqlalchemy.orm.mapper import _mapper_registry from sqlalchemy.orm.session import _sessions from sqlalchemy.util import jython import operator -from sqlalchemy.test import testing -from sqlalchemy import MetaData, Integer, String, ForeignKey, PickleType +from sqlalchemy.test import testing, engines +from sqlalchemy import MetaData, Integer, String, ForeignKey, PickleType, create_engine from sqlalchemy.test.schema import Table, Column import sqlalchemy as sa from sqlalchemy.sql import column from sqlalchemy.test.util import gc_collect import gc +import weakref from test.orm import _base if jython: @@ -26,6 +28,7 @@ class B(_base.ComparableEntity): def profile_memory(func): # run the test 50 times. if length of gc.get_objects() # keeps growing, assert false + def profile(*args): gc_collect() samples = [0 for x in range(0, 50)] @@ -33,6 +36,7 @@ def profile_memory(func): func(*args) gc_collect() samples[x] = len(gc.get_objects()) + print "sample gc sizes:", samples assert len(_sessions) == 0 @@ -130,6 +134,64 @@ class MemUsageTest(EnsureZeroed): del m1, m2, m3 assert_no_mappers() + @testing.crashes('sqlite', ':memory: connection not suitable here') + def test_orm_many_engines(self): + metadata = MetaData(testing.db) + + table1 = Table("mytable", metadata, + Column('col1', Integer, primary_key=True, test_needs_autoincrement=True), + Column('col2', String(30))) + + table2 = Table("mytable2", metadata, + Column('col1', Integer, primary_key=True, test_needs_autoincrement=True), + Column('col2', String(30)), + Column('col3', Integer, ForeignKey("mytable.col1"))) + + metadata.create_all() + + m1 = mapper(A, table1, properties={ + "bs":relationship(B, cascade="all, delete", order_by=table2.c.col1)}, + order_by=table1.c.col1) + m2 = mapper(B, table2) + + m3 = mapper(A, table1, non_primary=True) + + @profile_memory + def go(): + engine = engines.testing_engine(options={'logging_name':'FOO', 'pool_logging_name':'BAR'}) + sess = create_session(bind=engine) + + a1 = A(col2="a1") + a2 = A(col2="a2") + a3 = A(col2="a3") + a1.bs.append(B(col2="b1")) + a1.bs.append(B(col2="b2")) + a3.bs.append(B(col2="b3")) + for x in [a1,a2,a3]: + sess.add(x) + sess.flush() + sess.expunge_all() + + alist = sess.query(A).all() + eq_( + [ + A(col2="a1", bs=[B(col2="b1"), B(col2="b2")]), + A(col2="a2", bs=[]), + A(col2="a3", bs=[B(col2="b3")]) + ], + alist) + + for a in alist: + sess.delete(a) + sess.flush() + sess.close() + engine.dispose() + go() + + metadata.drop_all() + del m1, m2, m3 + assert_no_mappers() + def test_mapper_reset(self): metadata = MetaData(testing.db) |
