Rev 3020: Handle repositories that cannot be remotely locked in branch_implementations.test_locking. in http://people.ubuntu.com/~robertc/baz2.0/pack.read-locks

Robert Collins robertc at robertcollins.net
Mon Nov 26 02:05:28 GMT 2007


At http://people.ubuntu.com/~robertc/baz2.0/pack.read-locks

------------------------------------------------------------
revno: 3020
revision-id:robertc at robertcollins.net-20071126020511-udqau8afmvtulcxg
parent: robertc at robertcollins.net-20071126020303-7l85pl5tw4qznb5l
committer: Robert Collins <robertc at robertcollins.net>
branch nick: pack.read-locks
timestamp: Mon 2007-11-26 13:05:11 +1100
message:
  Handle repositories that cannot be remotely locked in branch_implementations.test_locking.
modified:
  bzrlib/tests/branch_implementations/test_locking.py test_locking.py-20060707151933-tav3o2hpibwi53u4-4
=== modified file 'bzrlib/tests/branch_implementations/test_locking.py'
--- a/bzrlib/tests/branch_implementations/test_locking.py	2007-04-18 05:10:19 +0000
+++ b/bzrlib/tests/branch_implementations/test_locking.py	2007-11-26 02:05:11 +0000
@@ -398,24 +398,33 @@
             except NotImplementedError:
                 # This branch doesn't support this API.
                 return
-            branch.repository.leave_lock_in_place()
-            repo_token = branch.repository.lock_write()
-            branch.repository.unlock()
+            try:
+                branch.repository.leave_lock_in_place()
+            except NotImplementedError:
+                # This repo doesn't support leaving locks around,
+                # assume it is essentially lock-free.
+                repo_token = None
+            else:
+                repo_token = branch.repository.lock_write()
+                branch.repository.unlock()
         finally:
             branch.unlock()
         # Reacquire the lock (with a different branch object) by using the
         # tokens.
         new_branch = branch.bzrdir.open_branch()
-        # We have to explicitly lock the repository first.
-        new_branch.repository.lock_write(token=repo_token)
+        if repo_token is not None:
+            # We have to explicitly lock the repository first.
+            new_branch.repository.lock_write(token=repo_token)
         new_branch.lock_write(token=token)
-        # Now we don't need our own repository lock anymore (the branch is
-        # holding it for us).
-        new_branch.repository.unlock()
+        if repo_token is not None:
+            # Now we don't need our own repository lock anymore (the branch is
+            # holding it for us).
+            new_branch.repository.unlock()
         # Call dont_leave_lock_in_place, so that the lock will be released by
         # this instance, even though the lock wasn't originally acquired by it.
         new_branch.dont_leave_lock_in_place()
-        new_branch.repository.dont_leave_lock_in_place()
+        if repo_token is not None:
+            new_branch.repository.dont_leave_lock_in_place()
         new_branch.unlock()
         # Now the branch (and repository) is unlocked.  Test this by locking it
         # without tokens.
@@ -437,8 +446,14 @@
         branch = branch.bzrdir.open_branch()
         branch.lock_write()
         try:
-            # Now the branch.repository is locked, so we can't lock it with a new
-            # repository without a token.
+            # The branch should have asked the rpeository to lock.
+            self.assertTrue(branch.repository.is_write_locked())
+            # Does the repository type actually lock?
+            if not branch.repository.get_physical_lock_status():
+                # The test was successfully applied, so it was applicable.
+                return
+            # Now the branch.repository is physically locked, so we can't lock
+            # it with a new repository instance.
             new_repo = branch.bzrdir.open_repository()
             self.assertRaises(errors.LockContention, new_repo.lock_write)
             # We can call lock_write on the original repository object though,



More information about the bazaar-commits mailing list