Rev 4712: Add a test which triggers the behavior. in http://bazaar.launchpad.net/~jameinel/bzr/2.0.4-495000-win32-autopack

John Arbash Meinel john at arbash-meinel.com
Wed Dec 16 22:00:54 GMT 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.0.4-495000-win32-autopack

------------------------------------------------------------
revno: 4712
revision-id: john at arbash-meinel.com-20091216220039-2y6zdrnoiao552l6
parent: john at arbash-meinel.com-20091216202004-22zb9k6mzx4a4cgu
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.0.4-495000-win32-autopack
timestamp: Wed 2009-12-16 16:00:39 -0600
message:
  Add a test which triggers the behavior.
  
  It is a bit more monkey patching than ideal, but works and is stable
  for now.
-------------- next part --------------
=== modified file 'bzrlib/tests/per_pack_repository.py'
--- a/bzrlib/tests/per_pack_repository.py	2009-09-07 03:00:23 +0000
+++ b/bzrlib/tests/per_pack_repository.py	2009-12-16 22:00:39 +0000
@@ -546,6 +546,42 @@
         finally:
             tree.unlock()
 
+    def test_concurrent_pack_during_autopack(self):
+        tree = self.make_branch_and_tree('tree')
+        tree.lock_write()
+        try:
+            for i in xrange(9):
+                tree.commit('rev %d' % (i,))
+            r2 = repository.Repository.open('tree')
+            r2.lock_write()
+            try:
+                # Monkey patch so that pack occurs while the other repo is
+                # autopacking. This is slightly bad, but all current pack
+                # repository implementations have a _pack_collection, and we
+                # test that it gets triggered. So if a future format changes
+                # things, the test will fail rather than succeed accidentally.
+                autopack_count = [0]
+                r1 = tree.branch.repository
+                orig = r1._pack_collection.pack_distribution
+                def trigger_during_auto(*args, **kwargs):
+                    ret = orig(*args, **kwargs)
+                    if not autopack_count[0]:
+                        r2.pack()
+                    autopack_count[0] += 1
+                    return ret
+                r1._pack_collection.pack_distribution = trigger_during_auto
+                tree.commit('autopack-rev')
+                # This triggers 2 autopacks. The first one causes r2.pack() to
+                # fire, but r2 doesn't see the new pack file yet. The
+                # autopack restarts and sees there are 2 files and there
+                # should be only 1 for 10 commits. So it goes ahead and
+                # finishes autopacking.
+                self.assertEqual([2], autopack_count)
+            finally:
+                r2.unlock()
+        finally:
+            tree.unlock()
+
     def test_lock_write_does_not_physically_lock(self):
         repo = self.make_repository('.', format=self.get_format())
         repo.lock_write()



More information about the bazaar-commits mailing list