Author: astaric
Date: Wed May 22 15:47:48 2013
New Revision: 1485255
URL: http://svn.apache.org/r1485255
Log:
Force trac to use separate db connections for different environments when
running tests.
Unittests in python2.7 run in the same process and share the same connection
pool. This basically means that all tests share the same in-memory database,
and calling reset_db in teardown methods destroys data prepared in __init__
of other tests. Trac tests do not do prepare data in __init__, but when run
with a product env, which stores config values to database, this behavior
causes multiple tests to fail.
We workaround this issue by monkey patching trac's ConnectionPool. We force
it to establish a separate connection for each DatabaseManager.
Modified:
bloodhound/trunk/bloodhound_multiproduct/tests/env.py
Modified: bloodhound/trunk/bloodhound_multiproduct/tests/env.py
URL:
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_multiproduct/tests/env.py?rev=1485255&r1=1485254&r2=1485255&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_multiproduct/tests/env.py (original)
+++ bloodhound/trunk/bloodhound_multiproduct/tests/env.py Wed May 22 15:47:48
2013
@@ -47,6 +47,23 @@ from multiproduct.api import MultiProduc
from multiproduct.env import ProductEnvironment
from multiproduct.model import Product
+# unittests in python2.7 run in the same process and share the same connection
+# pool. This basically means that all tests share the same in-memory database,
+# and calling reset_db in teardown methods destroys data prepared in __init__
+# of other tests. Trac tests do not do prepare data in __init__, but when run
+# with a product env, which stores config values to database, this behavior
+# causes multiple tests to fail.
+#
+# We workaround this issue by monkey patching trac's ConnectionPool. We force
+# it to establish a separate connection for each DatabaseManager.
+from trac.db.pool import ConnectionPool, ConnectionPoolBackend
+def ConnectionPool_get_cnx(self, timeout=None):
+ if not hasattr(self, '_backend'):
+ self._backend = ConnectionPoolBackend(1)
+ return self._backend.get_cnx(self._connector, self._kwargs, timeout)
+ConnectionPool.get_cnx = ConnectionPool_get_cnx
+
+
class ProductEnvironmentStub(ProductEnvironment):
r"""A product environment slightly tweaked for testing purposes
"""