[Checkins] SVN: relstorage/trunk/relstorage/tests/reltestbase.py Added a stress test of BTrees.Length conflict resolution.

Shane Hathaway shane at hathawaymix.org
Fri Jul 30 17:15:14 EDT 2010


Log message for revision 115249:
  Added a stress test of BTrees.Length conflict resolution.
  

Changed:
  U   relstorage/trunk/relstorage/tests/reltestbase.py

-=-
Modified: relstorage/trunk/relstorage/tests/reltestbase.py
===================================================================
--- relstorage/trunk/relstorage/tests/reltestbase.py	2010-07-30 21:14:36 UTC (rev 115248)
+++ relstorage/trunk/relstorage/tests/reltestbase.py	2010-07-30 21:15:14 UTC (rev 115249)
@@ -30,6 +30,7 @@
 from ZODB.tests.StorageTestBase import zodb_pickle
 from ZODB.tests.StorageTestBase import zodb_unpickle
 from ZODB.utils import p64
+import random
 import time
 import transaction
 
@@ -537,7 +538,55 @@
         finally:
             db.close()
 
+    def checkBTreesLengthStress(self):
+        # BTrees.Length objects are unusual Persistent objects: they
+        # set _p_independent and they frequently invoke conflict
+        # resolution. Run a stress test on them.
+        updates_per_thread = 50
+        thread_count = 4
 
+        from BTrees.Length import Length
+        db = DB(self._storage)
+        try:
+            c = db.open()
+            try:
+                c.root()['length'] = Length()
+                transaction.commit()
+            finally:
+                c.close()
+
+            def updater():
+                thread_db = DB(self._storage)
+                for i in range(updates_per_thread):
+                    thread_c = thread_db.open()
+                    try:
+                        thread_c.root()['length'].change(1)
+                        time.sleep(random.random() * 0.05)
+                        transaction.commit()
+                    finally:
+                        thread_c.close()
+
+            import threading
+            threads = []
+            for i in range(thread_count):
+                t = threading.Thread(target=updater)
+                threads.append(t)
+            for t in threads:
+                t.start()
+            for t in threads:
+                t.join(120)
+
+            c = db.open()
+            try:
+                self.assertEqual(c.root()['length'](),
+                    updates_per_thread * thread_count)
+            finally:
+                transaction.abort()
+                c.close()
+
+        finally:
+            db.close()
+
 class DoubleCommitter(Persistent):
     """A crazy persistent class that changes self in __getstate__"""
     def __getstate__(self):



More information about the checkins mailing list