OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
tandrii(chromium)
2016/06/13 17:03:28
nit 2016
Sergiy Byelozyorov
2016/06/14 06:12:14
Done.
| |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 | |
6 import threading | |
7 import unittest | |
8 | |
9 | |
10 class ThreadWatcherMixIn(object): | |
11 def setUp(self): | |
12 self._pre_test_threads = [t.ident for t in threading.enumerate()] | |
tandrii(chromium)
2016/06/13 17:03:28
strictly speaking, these numbers can be re-used.
Sergiy Byelozyorov
2016/06/14 06:12:14
Agree, but I am not sure how otherwise we can chec
| |
13 | |
14 def tearDown(self): | |
15 new_threads = [t for t in threading.enumerate() | |
16 if t.ident not in self._pre_test_threads] | |
17 if new_threads: | |
18 self.fail('Found %d running thread(s) after the test: %s' % ( | |
19 len(new_threads), ', '.join(t.name for t in new_threads))) | |
tandrii(chromium)
2016/06/13 17:03:28
t.name is usually not given, at least in infra lan
Sergiy Byelozyorov
2016/06/14 06:12:14
t.name defaults to Thread-NN, where NN-some unique
tandrii(chromium)
2016/06/14 10:21:43
Yes, and as result both suck for debugging, unless
Sergiy Byelozyorov
2016/06/14 19:47:01
Done.
| |
20 | |
21 | |
22 | |
23 class TestCase(unittest.TestCase, ThreadWatcherMixIn): | |
24 """Base unittest class that cleans off a trial directory in tearDown().""" | |
25 def setUp(self): | |
26 super(TestCase, self).setUp() | |
27 ThreadWatcherMixIn.setUp(self) | |
28 | |
29 def tearDown(self): | |
30 ThreadWatcherMixIn.tearDown(self) | |
31 super(TestCase, self).tearDown() | |
OLD | NEW |