Rev 4535: Update the test_selftest tests so that they pass again. in lp:///~jameinel/bzr/1.18-lock-warnings

John Arbash Meinel john at arbash-meinel.com
Fri Jul 31 17:20:18 BST 2009


At lp:///~jameinel/bzr/1.18-lock-warnings

------------------------------------------------------------
revno: 4535
revision-id: john at arbash-meinel.com-20090731161812-6dnu3sy885w1njzi
parent: john at arbash-meinel.com-20090731160627-66v64hqnoxzkgi2v
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.18-lock-warnings
timestamp: Fri 2009-07-31 11:18:12 -0500
message:
  Update the test_selftest tests so that they pass again.
  
  Things should pass both with and without -Edisable_lock_checks.
  Also default to having the strict lock checking to 'on'.
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2009-07-31 16:06:27 +0000
+++ b/bzrlib/tests/__init__.py	2009-07-31 16:18:12 +0000
@@ -830,8 +830,8 @@
         self._preserved_debug_flags = set(debug.debug_flags)
         if 'allow_debug' not in selftest_debug_flags:
             debug.debug_flags.clear()
-        # if 'disable_lock_checks' not in selftest_debug_flags:
-        #     debug.debug_flags.add('strict_locks')
+        if 'disable_lock_checks' not in selftest_debug_flags:
+            debug.debug_flags.add('strict_locks')
         self.addCleanup(self._restore_debug_flags)
 
     def _clear_hooks(self):
@@ -1312,13 +1312,16 @@
         """Make the logfile not be deleted when _finishLogFile is called."""
         self._keep_log_file = True
 
-    def failsStrictLockCheck(self):
+    def thisFailsStrictLockCheck(self):
         """It is known that this test would fail with -Dstrict_locks.
 
         By default, all tests are run with strict lock checking unless
         -Edisable_lock_checks is supplied. However there are some tests which
         we know fail strict locks at this point that have not been fixed.
         They should call this function to disable the strict checking.
+
+        This should be used sparingly, it is much better to fix the locking
+        issues rather than papering over the problem by calling this function.
         """
         debug.debug_flags.discard('strict_locks')
 

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2009-07-31 16:06:27 +0000
+++ b/bzrlib/tests/test_selftest.py	2009-07-31 16:18:12 +0000
@@ -597,7 +597,12 @@
                 l.attempt_lock()
         test = TestDanglingLock('test_function')
         result = test.run()
-        self.assertEqual(1, len(result.errors))
+        if self._lock_check_thorough:
+            self.assertEqual(1, len(result.errors))
+        else:
+            # When _lock_check_thorough is disabled, then we don't trigger a
+            # failure
+            self.assertEqual(0, len(result.errors))
 
 
 class TestTestCaseWithTransport(tests.TestCaseWithTransport):
@@ -1405,7 +1410,10 @@
         # we could set something and run a test that will check
         # it gets santised, but this is probably sufficient for now:
         # if someone runs the test with -Dsomething it will error.
-        self.assertEqual(set(), bzrlib.debug.debug_flags)
+        flags = set()
+        if self._lock_check_thorough:
+            flags.add('strict_locks')
+        self.assertEqual(flags, bzrlib.debug.debug_flags)
 
     def change_selftest_debug_flags(self, new_flags):
         orig_selftest_flags = tests.selftest_debug_flags
@@ -1426,7 +1434,10 @@
                 self.flags = set(bzrlib.debug.debug_flags)
         test = TestThatRecordsFlags('test_foo')
         test.run(self.make_test_result())
-        self.assertEqual(set(['a-flag']), self.flags)
+        flags = set(['a-flag'])
+        if 'disable_lock_checks' not in tests.selftest_debug_flags:
+            flags.add('strict_locks')
+        self.assertEqual(flags, self.flags)
 
     def test_disable_lock_checks(self):
         """The -Edisable_lock_checks flag disables thorough checks."""
@@ -1434,12 +1445,14 @@
             def test_foo(nested_self):
                 self.flags = set(bzrlib.debug.debug_flags)
                 self.test_lock_check_thorough = nested_self._lock_check_thorough
+        self.change_selftest_debug_flags(set())
         test = TestThatRecordsFlags('test_foo')
         test.run(self.make_test_result())
+        # By default we do strict lock checking and thorough lock/unlock
+        # tracking.
         self.assertTrue(self.test_lock_check_thorough)
-        self.assertEqual(set(), self.flags)
-        # Now set the disable_lock_checks flag, and assert that this is
-        # no longer true
+        self.assertEqual(set(['strict_locks']), self.flags)
+        # Now set the disable_lock_checks flag, and show that this changed.
         self.change_selftest_debug_flags(set(['disable_lock_checks']))
         test = TestThatRecordsFlags('test_foo')
         test.run(self.make_test_result())



More information about the bazaar-commits mailing list