[Checkins] SVN: gocept.selenium/branches/wosc-zodb-isolation/src/gocept/selenium/tests/ Add tests to ensure requests have isolated ZODB connections

Wolfgang Schnerring wosc at wosc.de
Sat Dec 25 09:37:47 EST 2010


Log message for revision 119083:
  Add tests to ensure requests have isolated ZODB connections
  

Changed:
  U   gocept.selenium/branches/wosc-zodb-isolation/src/gocept/selenium/tests/fixture/configure.zcml
  U   gocept.selenium/branches/wosc-zodb-isolation/src/gocept/selenium/tests/fixture/dummy.py
  U   gocept.selenium/branches/wosc-zodb-isolation/src/gocept/selenium/tests/isolation.py

-=-
Modified: gocept.selenium/branches/wosc-zodb-isolation/src/gocept/selenium/tests/fixture/configure.zcml
===================================================================
--- gocept.selenium/branches/wosc-zodb-isolation/src/gocept/selenium/tests/fixture/configure.zcml	2010-12-25 14:37:04 UTC (rev 119082)
+++ gocept.selenium/branches/wosc-zodb-isolation/src/gocept/selenium/tests/fixture/configure.zcml	2010-12-25 14:37:46 UTC (rev 119083)
@@ -19,6 +19,13 @@
 
   <browser:page
     for="*"
+    name="inc-volatile.html"
+    class=".dummy.IncrementVolatile"
+    permission="zope.Public"
+    />
+
+  <browser:page
+    for="*"
     name="error.html"
     class=".dummy.Error"
     permission="zope.Public"

Modified: gocept.selenium/branches/wosc-zodb-isolation/src/gocept/selenium/tests/fixture/dummy.py
===================================================================
--- gocept.selenium/branches/wosc-zodb-isolation/src/gocept/selenium/tests/fixture/dummy.py	2010-12-25 14:37:04 UTC (rev 119082)
+++ gocept.selenium/branches/wosc-zodb-isolation/src/gocept/selenium/tests/fixture/dummy.py	2010-12-25 14:37:46 UTC (rev 119083)
@@ -34,3 +34,16 @@
 
     def __call__(Self):
         raise ValueError()
+
+
+class IncrementVolatile(object):
+
+    def __call__(self):
+        c = zope.security.proxy.removeSecurityProxy(self.context)
+        if hasattr(c, 'aq_base'):
+            c = c.aq_base
+
+        if not hasattr(c, '_v_counter'):
+            c._v_counter = 0
+        c._v_counter += 1
+        return str(c._v_counter)

Modified: gocept.selenium/branches/wosc-zodb-isolation/src/gocept/selenium/tests/isolation.py
===================================================================
--- gocept.selenium/branches/wosc-zodb-isolation/src/gocept/selenium/tests/isolation.py	2010-12-25 14:37:04 UTC (rev 119082)
+++ gocept.selenium/branches/wosc-zodb-isolation/src/gocept/selenium/tests/isolation.py	2010-12-25 14:37:46 UTC (rev 119083)
@@ -17,6 +17,16 @@
 
 class IsolationTests(object):
 
+    # test_0_set and test_1_get verify that different test methods are isolated
+    # from each other, i.e. that the underlying DemoStorage stacking is wired
+    # up correctly
+
+    def getRootFolder(self):
+        raise NotImplementedError()
+
+    def getDatabase(self):
+        raise NotImplementedError()
+
     def test_0_set(self):
         global ENSURE_ORDER
         self.selenium.open('http://%s/set.html' % self.selenium.server)
@@ -31,3 +41,33 @@
         self.selenium.open('http://%s/get.html' % self.selenium.server)
         self.selenium.assertNotBodyText('1')
         ENSURE_ORDER = False
+
+    def test_each_request_gets_a_separate_zodb_connection(self):
+        self.selenium.open(
+            'http://%s/inc-volatile.html' % self.selenium.server)
+        self.selenium.assertBodyText('1')
+        # We demonstrate isolation using volatile attributes (which are
+        # guaranteed not to be present on separate connections). But since
+        # there is no guarantee that volatile attributes disappear on
+        # transaction boundaries, we need to prevent re-use of the first
+        # connection -- to avoid trouble like "it's the same connection, so the
+        # volatile attribute is still there".
+        #
+        # The proper way to do this would be two requests that are processing
+        # concurrently, but a) gocept.selenium is not prepared for
+        # multi-threaded requests and b) simulating that would be a major pain,
+        # so we cheat and force the opening of another connection by claiming
+        # one here.
+        db = self.getDatabase()
+        conn = db.open()
+        self.selenium.open(
+            'http://%s/inc-volatile.html' % self.selenium.server)
+        conn.close()
+        self.selenium.assertBodyText('1')
+
+    def test_requests_get_different_zodb_connection_than_tests(self):
+        root = self.getRootFolder()
+        root._v_counter = 1
+        self.selenium.open(
+            'http://%s/inc-volatile.html' % self.selenium.server)
+        self.selenium.assertBodyText('1')



More information about the checkins mailing list