Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Unified Diff: testing_support/thread_watcher.py

Issue 2127943002: Thread Watcher: don't fail when test already failed. (Closed) Base URL: https://chromium.googlesource.com/infra/testing/testing_support.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing_support/thread_watcher.py
diff --git a/testing_support/thread_watcher.py b/testing_support/thread_watcher.py
index ca5180bad59f101c4da41700586ec3b6663d86b5..5584f8125e30947c1afd36e86d44ebf51d1f4812 100644
--- a/testing_support/thread_watcher.py
+++ b/testing_support/thread_watcher.py
@@ -3,6 +3,7 @@
# found in the LICENSE file.
+import logging
import sys
import threading
import traceback
@@ -30,9 +31,29 @@ class ThreadWatcherMixIn(object):
details.append(' Thread stopped while acquiring stacktrace.\n')
details = ''.join(details)
- self.fail('Found %d running thread(s) after the test.\n%s' % (
- len(new_threads), details))
+ msg = 'Found %d running thread(s) after the test.\n%s' % (
+ len(new_threads), details)
+ if self._should_fail():
+ self.fail(msg) # This raises exception.
+ # Test failed before this check, so don't raise another exception
Sergiy Byelozyorov 2016/07/07 07:05:01 IMHO this comment should be before line 36 and IMH
tandrii(chromium) 2016/07/07 11:47:05 Done.
+ # overwriting the original one, and making it harder to debug.
+ # Besides, that exception might be the reason cleanup didn't happen.
+ logging.warn(msg)
+ logging.warn('Note: extra running threads might be due to your test '
+ 'failure, which prevented *your cleanup code* from '
+ 'executing.')
+ def _should_fail(self):
Sergiy Byelozyorov 2016/07/07 07:05:01 suggestion: rename to _test_likely_passed(self):
tandrii(chromium) 2016/07/07 11:47:05 Done.
+ """Conservatively returns True if current test has likely not failed yet."""
Sergiy Byelozyorov 2016/07/07 07:05:01 How about this? """Conservatively returns True if
tandrii(chromium) 2016/07/07 11:47:05 Done.
+ # When run using unittest runner,
+ # self._resultForDoCleanups is set to internal unittest object.
+ if hasattr(self, '_resultForDoCleanups') and self._resultForDoCleanups:
+ return self._resultForDoCleanups.wasSuccessful()
+ # expect_tests runner does so differently.
+ if hasattr(self, '_test_failed_with_exception'):
+ return not self._test_failed_with_exception
+ # Default case - be conservative.
+ return True
class TestCase(unittest.TestCase, ThreadWatcherMixIn):
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698