[Checkins] SVN: relstorage/trunk/relstorage/ Added a failing test that could explain the history-free packing bug that Chris Withers exposed.

Shane Hathaway shane at hathawaymix.org
Fri Jan 28 20:13:50 EST 2011


Log message for revision 119995:
  Added a failing test that could explain the history-free packing bug that Chris Withers exposed.
  

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

-=-
Modified: relstorage/trunk/relstorage/adapters/packundo.py
===================================================================
--- relstorage/trunk/relstorage/adapters/packundo.py	2011-01-28 22:40:08 UTC (rev 119994)
+++ relstorage/trunk/relstorage/adapters/packundo.py	2011-01-29 01:13:49 UTC (rev 119995)
@@ -50,6 +50,9 @@
         finally:
             self.connmanager.close(conn, cursor)
 
+    def on_filling_object_refs(self):
+        """Test injection point"""
+
     def fill_object_refs(self, conn, cursor, get_references):
         """Update the object_refs table by analyzing new transactions."""
         if self.keep_history:
@@ -74,6 +77,7 @@
         self.runner.run_script_stmt(cursor, stmt)
         tids = [tid for (tid,) in cursor]
         if tids:
+            self.on_filling_object_refs()
             added = 0
             log.info("discovering references from objects in %d "
                 "transaction(s)" % len(tids))

Modified: relstorage/trunk/relstorage/tests/reltestbase.py
===================================================================
--- relstorage/trunk/relstorage/tests/reltestbase.py	2011-01-28 22:40:08 UTC (rev 119994)
+++ relstorage/trunk/relstorage/tests/reltestbase.py	2011-01-29 01:13:49 UTC (rev 119995)
@@ -544,6 +544,38 @@
         finally:
             db.close()
 
+    def checkPackWhileReferringObjectChanges(self):
+        # Packing should not remove objects referenced by an
+        # object that changes during packing.
+        db = DB(self._storage)
+        try:
+            # add some data to be packed
+            c = db.open()
+            root = c.root()
+            child = PersistentMapping()
+            root['child'] = child
+            transaction.commit()
+            expect_oids = [child._p_oid]
+
+            def inject_changes():
+                child2 = PersistentMapping()
+                root['child2'] = child2
+                transaction.commit()
+                expect_oids.append(child2._p_oid)
+
+            adapter = self._storage._adapter
+            adapter.packundo.on_filling_object_refs = inject_changes
+            packtime = time.time()
+            self._storage.pack(packtime, referencesf)
+
+            self.assertEqual(len(expect_oids), 2,
+                "The on_filling_object_refs hook was never called")
+            # Both children should still exist.
+            self._storage.load(expect_oids[0], '')
+            self._storage.load(expect_oids[1], '')
+        finally:
+            db.close()
+
     def checkPackBrokenPickle(self):
         # Verify the pack stops with the right exception if it encounters
         # a broken pickle.



More information about the checkins mailing list