Commit ac8ffd9e authored by Stefan H. Holek's avatar Stefan H. Holek

Explicitly close connections to "sandbox" databases.

parent dc9b9512
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
- ZopeLite now takes care not to monkey patch an already started Zope. - ZopeLite now takes care not to monkey patch an already started Zope.
- PortalTestCase no longer calls _refreshSkinData() as CMF is smart enough - PortalTestCase no longer calls _refreshSkinData() as CMF is smart enough
now (and CMF 1.5+ does not work that way anyway). now (and CMF 1.5+ does not work that way anyway).
- Fixed a bug where using sessions in sandboxed (functional) tests would cause
connection pool depletion and subsequent hangs. Thanks to Balazs Ree.
0.9.6 0.9.6
- Dropped support for Zope 2.5 as it lacks the setSecurityManager() API. - Dropped support for Zope 2.5 as it lacks the setSecurityManager() API.
......
...@@ -17,6 +17,7 @@ $Id: sandbox.py,v 1.2 2004/08/19 15:31:26 shh42 Exp $ ...@@ -17,6 +17,7 @@ $Id: sandbox.py,v 1.2 2004/08/19 15:31:26 shh42 Exp $
import ZopeLite as Zope2 import ZopeLite as Zope2
import transaction import transaction
import base
import utils import utils
...@@ -31,6 +32,7 @@ class Sandboxed: ...@@ -31,6 +32,7 @@ class Sandboxed:
def _app(self): def _app(self):
'''Returns the app object for a test.''' '''Returns the app object for a test.'''
app = Zope2.app(Zope2.sandbox().open()) app = Zope2.app(Zope2.sandbox().open())
base._connections.register(app._p_jar)
AppZapper().set(app) AppZapper().set(app)
return utils.makerequest(app) return utils.makerequest(app)
...@@ -38,6 +40,7 @@ class Sandboxed: ...@@ -38,6 +40,7 @@ class Sandboxed:
'''Clears the transaction and the AppZapper.''' '''Clears the transaction and the AppZapper.'''
transaction.abort() transaction.abort()
AppZapper().clear() AppZapper().clear()
base.closeConnections()
class AppZapper: class AppZapper:
......
...@@ -105,11 +105,27 @@ class TestShoppingCart(ZopeTestCase.ZopeTestCase): ...@@ -105,11 +105,27 @@ class TestShoppingCart(ZopeTestCase.ZopeTestCase):
self.cart.addItems([DummyOrder('510-007', 2),]) self.cart.addItems([DummyOrder('510-007', 2),])
self.assertEqual(self.cart.getTotal(), 149.95) self.assertEqual(self.cart.getTotal(), 149.95)
def testGetItem(self):
# Getting an item from the "database" should work
item = self.cart.getItem('510-115')
self.assertEqual(item['id'], '510-115')
self.assertEqual(item['title'], 'Econo Feeder')
self.assertEqual(item['price'], 7.95)
def testEight(self):
# Additional test to trigger connection pool depletion bug
pass
class TestSandboxedShoppingCart(ZopeTestCase.Sandboxed, TestShoppingCart):
'''Demonstrate that sessions work in sandboxes'''
def test_suite(): def test_suite():
from unittest import TestSuite, makeSuite from unittest import TestSuite, makeSuite
suite = TestSuite() suite = TestSuite()
suite.addTest(makeSuite(TestShoppingCart)) suite.addTest(makeSuite(TestShoppingCart))
suite.addTest(makeSuite(TestSandboxedShoppingCart))
return suite return suite
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment