Rev 4790: Fix per_workingtree.test_workingtree.test_merge_revert in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b4-win32-merge-inner

John Arbash Meinel john at arbash-meinel.com
Sun Nov 8 05:29:09 GMT 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b4-win32-merge-inner

------------------------------------------------------------
revno: 4790
revision-id: john at arbash-meinel.com-20091108052857-pdgy3ty2fjxuvult
parent: pqm at pqm.ubuntu.com-20091106084512-t5ll6xywcd1bycfe
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0b4-win32-merge-inner
timestamp: Sat 2009-11-07 23:28:57 -0600
message:
  Fix per_workingtree.test_workingtree.test_merge_revert
  
  Something about merge_inner breaks if you don't pass in locked objects.
  My guess is that it uses 'tree.basis_tree()' but doesn't hold the
  lock on 'tree' for the lifetime of 'basis_tree'.
  Anyway, locking first helps with 3 more tests passing, and removes
  a test which self.thisFailsStrictLockCheck().
-------------- next part --------------
=== modified file 'bzrlib/tests/per_workingtree/test_workingtree.py'
--- a/bzrlib/tests/per_workingtree/test_workingtree.py	2009-08-20 04:09:58 +0000
+++ b/bzrlib/tests/per_workingtree/test_workingtree.py	2009-11-08 05:28:57 +0000
@@ -513,30 +513,37 @@
 
     def test_merge_revert(self):
         from bzrlib.merge import merge_inner
-        self.thisFailsStrictLockCheck()
         this = self.make_branch_and_tree('b1')
-        open('b1/a', 'wb').write('a test\n')
-        this.add('a')
-        open('b1/b', 'wb').write('b test\n')
-        this.add('b')
+        self.build_tree_contents([('b1/a', 'a test\n'), ('b1/b', 'b test\n')])
+        this.add(['a', 'b'])
         this.commit(message='')
         base = this.bzrdir.clone('b2').open_workingtree()
-        open('b2/a', 'wb').write('b test\n')
+        self.build_tree_contents([('b2/a', 'b test\n')])
         other = this.bzrdir.clone('b3').open_workingtree()
-        open('b3/a', 'wb').write('c test\n')
-        open('b3/c', 'wb').write('c test\n')
+        self.build_tree_contents([('b3/a', 'c test\n'), ('b3/c', 'c test\n')])
         other.add('c')
 
-        open('b1/b', 'wb').write('q test\n')
-        open('b1/d', 'wb').write('d test\n')
+        self.build_tree_contents([('b1/b', 'q test\n'), ('b1/d', 'd test\n')])
+        # Note: If we don't lock this before calling merge_inner, then we get a
+        #       lock-contention failure. This probably indicates something
+        #       weird going on inside merge_inner. Probably something about
+        #       calling bt = this_tree.basis_tree() in one lock, and then
+        #       locking both this_tree and bt separately, causing a dirstate
+        #       locking race.
+        this.lock_write()
+        self.addCleanup(this.unlock)
         merge_inner(this.branch, other, base, this_tree=this)
-        self.assertNotEqual(open('b1/a', 'rb').read(), 'a test\n')
+        a = open('b1/a', 'rb')
+        try:
+            self.assertNotEqual(a.read(), 'a test\n')
+        finally:
+            a.close()
         this.revert()
-        self.assertEqual(open('b1/a', 'rb').read(), 'a test\n')
-        self.assertIs(os.path.exists('b1/b.~1~'), True)
-        self.assertIs(os.path.exists('b1/c'), False)
-        self.assertIs(os.path.exists('b1/a.~1~'), False)
-        self.assertIs(os.path.exists('b1/d'), True)
+        self.assertFileEqual('a test\n', 'b1/a')
+        self.failUnlessExists('b1/b.~1~')
+        self.failIfExists('b1/c')
+        self.failIfExists('b1/a.~1~')
+        self.failUnlessExists('b1/d')
 
     def test_update_updates_bound_branch_no_local_commits(self):
         # doing an update in a tree updates the branch its bound to too.



More information about the bazaar-commits mailing list