Rev 4331: Fix lock test failures by taking lock breaking into account. in file:///home/vila/src/bzr/experimental/failing-lock-tests/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri May 8 16:58:02 BST 2009


At file:///home/vila/src/bzr/experimental/failing-lock-tests/

------------------------------------------------------------
revno: 4331
revision-id: v.ladeuil+lp at free.fr-20090508155800-svg2sw0dp40udwq5
parent: v.ladeuil+lp at free.fr-20090508154027-r450tion5jpua558
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: failing-lock-tests
timestamp: Fri 2009-05-08 17:58:00 +0200
message:
  Fix lock test failures by taking lock breaking into account.
  
  * tests/test_lockdir.py:
  (TestLockDir.test_43_break): Release the lock after breaking and
  acquiring it.
  
  * tests/__init__.py:
  (TestCase._check_locks): Consider lock breaks as releases.
  (TestCase._track_locks, TestCase._lock_broken): Also track broken locks.
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2009-05-04 22:12:01 +0000
+++ b/bzrlib/tests/__init__.py	2009-05-08 15:58:00 +0000
@@ -862,15 +862,19 @@
         # matching has occured with -Dlock.
         # unhook:
         acquired_locks = [lock for action, lock in self._lock_actions
-            if action == 'acquired']
+                          if action == 'acquired']
         released_locks = [lock for action, lock in self._lock_actions
-            if action == 'released']
+                          if action == 'released']
+        broken_locks = [lock for action, lock in self._lock_actions
+                        if action == 'broken']
         # trivially, given the tests for lock acquistion and release, if we
-        # have as many in each list, it should be ok.
-        if len(acquired_locks) != len(released_locks):
-            message = \
-                ("Different number of acquired and released locks. (%s, %s)" %
-                (acquired_locks, released_locks))
+        # have as many in each list, it should be ok. Some lock tests also
+        # break some locks on purpose and should be taken into account by
+        # considering that breaking a lock is just a dirty way of releasing it.
+        if len(acquired_locks) != (len(released_locks) + len(broken_locks)):
+            message = ('Different number of acquired and '
+                       'released or broken locks. (%s, %s + %s)' %
+                       (acquired_locks, released_locks, broken_locks))
             if not self._lock_check_thorough:
                 # Rather than fail, just warn
                 print "Broken test %s: %s" % (self, message)
@@ -882,8 +886,12 @@
         self._lock_actions = []
         self._lock_check_thorough = 'lock' in debug.debug_flags
         self.addCleanup(self._check_locks)
-        _mod_lock.Lock.hooks.install_named_hook('lock_acquired', self._lock_acquired, None)
-        _mod_lock.Lock.hooks.install_named_hook('lock_released', self._lock_released, None)
+        _mod_lock.Lock.hooks.install_named_hook('lock_acquired',
+                                                self._lock_acquired, None)
+        _mod_lock.Lock.hooks.install_named_hook('lock_released',
+                                                self._lock_released, None)
+        _mod_lock.Lock.hooks.install_named_hook('lock_broken',
+                                                self._lock_broken, None)
 
     def _lock_acquired(self, result):
         self._lock_actions.append(('acquired', result))
@@ -891,6 +899,9 @@
     def _lock_released(self, result):
         self._lock_actions.append(('released', result))
 
+    def _lock_broken(self, result):
+        self._lock_actions.append(('broken', result))
+
     def _ndiff_strings(self, a, b):
         """Return ndiff between two strings containing lines.
 

=== modified file 'bzrlib/tests/test_lockdir.py'
--- a/bzrlib/tests/test_lockdir.py	2009-05-08 15:40:27 +0000
+++ b/bzrlib/tests/test_lockdir.py	2009-05-08 15:58:00 +0000
@@ -490,6 +490,7 @@
         lf2.force_break(holder_info)
         # now we should be able to take it
         lf2.attempt_lock()
+        self.addCleanup(lf2.unlock)
         lf2.confirm()
 
     def test_44_break_already_released(self):



More information about the bazaar-commits mailing list