862
862
# matching has occured with -Dlock.
864
864
acquired_locks = [lock for action, lock in self._lock_actions
865
if action == 'acquired']
865
if action == 'acquired']
866
866
released_locks = [lock for action, lock in self._lock_actions
867
if action == 'released']
867
if action == 'released']
868
broken_locks = [lock for action, lock in self._lock_actions
869
if action == 'broken']
868
870
# trivially, given the tests for lock acquistion and release, if we
869
# have as many in each list, it should be ok.
870
if len(acquired_locks) != len(released_locks):
872
("Different number of acquired and released locks. (%s, %s)" %
873
(acquired_locks, released_locks))
871
# have as many in each list, it should be ok. Some lock tests also
872
# break some locks on purpose and should be taken into account by
873
# considering that breaking a lock is just a dirty way of releasing it.
874
if len(acquired_locks) != (len(released_locks) + len(broken_locks)):
875
message = ('Different number of acquired and '
876
'released or broken locks. (%s, %s + %s)' %
877
(acquired_locks, released_locks, broken_locks))
874
878
if not self._lock_check_thorough:
875
879
# Rather than fail, just warn
876
880
print "Broken test %s: %s" % (self, message)
882
886
self._lock_actions = []
883
887
self._lock_check_thorough = 'lock' in debug.debug_flags
884
888
self.addCleanup(self._check_locks)
885
_mod_lock.Lock.hooks.install_named_hook('lock_acquired', self._lock_acquired, None)
886
_mod_lock.Lock.hooks.install_named_hook('lock_released', self._lock_released, None)
889
_mod_lock.Lock.hooks.install_named_hook('lock_acquired',
890
self._lock_acquired, None)
891
_mod_lock.Lock.hooks.install_named_hook('lock_released',
892
self._lock_released, None)
893
_mod_lock.Lock.hooks.install_named_hook('lock_broken',
894
self._lock_broken, None)
888
896
def _lock_acquired(self, result):
889
897
self._lock_actions.append(('acquired', result))
891
899
def _lock_released(self, result):
892
900
self._lock_actions.append(('released', result))
902
def _lock_broken(self, result):
903
self._lock_actions.append(('broken', result))
894
905
def _ndiff_strings(self, a, b):
895
906
"""Return ndiff between two strings containing lines.