850
852
ui.ui_factory = ui.SilentUIFactory()
851
853
self.addCleanup(_restore)
855
def _check_locks(self):
856
"""Check that all lock take/release actions have been paired."""
857
# once we have fixed all the current lock problems, we can change the
858
# following code to always check for mismatched locks, but only do
859
# traceback showing with -Dlock (self._lock_check_thorough is True).
860
# For now, because the test suite will fail, we only assert that lock
861
# matching has occured with -Dlock.
863
acquired_locks = [lock for action, lock in self._lock_actions
864
if action == 'acquired']
865
released_locks = [lock for action, lock in self._lock_actions
866
if action == 'released']
867
# trivially, given the tests for lock acquistion and release, if we
868
# have as many in each list, it should be ok.
869
if len(acquired_locks) != len(released_locks):
871
("Different number of acquired and released locks. (%s, %s)" %
872
(acquired_locks, released_locks))
873
if not self._lock_check_thorough:
874
# Rather than fail, just warn
875
print "Broken test %s: %s" % (self, message)
879
def _track_locks(self):
880
"""Track lock activity during tests."""
881
self._lock_actions = []
882
self._lock_check_thorough = 'lock' in debug.debug_flags
883
self.addCleanup(self._check_locks)
884
_mod_lock.Lock.hooks.install_named_hook('lock_acquired', self._lock_acquired, None)
885
_mod_lock.Lock.hooks.install_named_hook('lock_released', self._lock_released, None)
887
def _lock_acquired(self, result):
888
self._lock_actions.append(('acquired', result))
890
def _lock_released(self, result):
891
self._lock_actions.append(('released', result))
853
893
def _ndiff_strings(self, a, b):
854
894
"""Return ndiff between two strings containing lines.