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

Unified Diff: testing_support/thread_watcher.py

Issue 2067533002: Check for stray threads from tests and fail if found (Closed) Base URL: https://chromium.googlesource.com/infra/testing/testing_support.git@master
Patch Set: Addressed comments Created 4 years, 6 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 | « testing_support/tests/thread_watcher_test.py ('k') | 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
new file mode 100644
index 0000000000000000000000000000000000000000..2a5dc1683ca2c9ebb53549a484f766591adec89f
--- /dev/null
+++ b/testing_support/thread_watcher.py
@@ -0,0 +1,31 @@
+# Copyright (c) 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+import threading
+import unittest
+
+
+class ThreadWatcherMixIn(object):
+ def setUp(self):
+ self._pre_test_threads = [t.ident for t in threading.enumerate()]
+
+ def tearDown(self):
+ new_threads = [t for t in threading.enumerate()
+ if t.ident not in self._pre_test_threads]
+ if new_threads:
+ self.fail('Found %d running thread(s) after the test: %s' % (
+ len(new_threads), ', '.join(t.name for t in new_threads)))
+
+
+
+class TestCase(unittest.TestCase, ThreadWatcherMixIn):
+ """Base unittest class that cleans off a trial directory in tearDown()."""
tandrii(chromium) 2016/06/14 10:21:43 update doc
Sergiy Byelozyorov 2016/06/14 19:47:01 Done.
+ def setUp(self):
+ super(TestCase, self).setUp()
+ ThreadWatcherMixIn.setUp(self)
+
+ def tearDown(self):
+ ThreadWatcherMixIn.tearDown(self)
+ super(TestCase, self).tearDown()
« no previous file with comments | « testing_support/tests/thread_watcher_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698