Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-31249: test_concurrent_futures checks dangling threads #3167

Merged
merged 1 commit into from
Aug 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions Lib/test/test_concurrent_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,20 @@ def my_method(self):
pass


class BaseTestCase(unittest.TestCase):
def setUp(self):
self._thread_key = test.support.threading_setup()

def tearDown(self):
test.support.reap_children()
test.support.threading_cleanup(*self._thread_key)


class ExecutorMixin:
worker_count = 5

def setUp(self):
self._thread_cleanup = test.support.threading_setup()
super().setUp()

self.t1 = time.time()
try:
Expand All @@ -81,8 +90,7 @@ def tearDown(self):
print("%.2fs" % dt, end=' ')
self.assertLess(dt, 60, "synchronization issue: test lasted too long")

test.support.threading_cleanup(*self._thread_cleanup)
test.support.reap_children()
super().tearDown()

def _prime_executor(self):
# Make sure that the executor is ready to do work before running the
Expand Down Expand Up @@ -130,7 +138,7 @@ def test_hang_issue12364(self):
f.result()


class ThreadPoolShutdownTest(ThreadPoolMixin, ExecutorShutdownTest, unittest.TestCase):
class ThreadPoolShutdownTest(ThreadPoolMixin, ExecutorShutdownTest, BaseTestCase):
def _prime_executor(self):
pass

Expand Down Expand Up @@ -185,7 +193,7 @@ def test_thread_names_default(self):
t.join()


class ProcessPoolShutdownTest(ProcessPoolMixin, ExecutorShutdownTest, unittest.TestCase):
class ProcessPoolShutdownTest(ProcessPoolMixin, ExecutorShutdownTest, BaseTestCase):
def _prime_executor(self):
pass

Expand Down Expand Up @@ -322,7 +330,7 @@ def test_timeout(self):
self.assertEqual(set([future2]), pending)


class ThreadPoolWaitTests(ThreadPoolMixin, WaitTests, unittest.TestCase):
class ThreadPoolWaitTests(ThreadPoolMixin, WaitTests, BaseTestCase):

def test_pending_calls_race(self):
# Issue #14406: multi-threaded race condition when waiting on all
Expand All @@ -340,7 +348,7 @@ def future_func():
sys.setswitchinterval(oldswitchinterval)


class ProcessPoolWaitTests(ProcessPoolMixin, WaitTests, unittest.TestCase):
class ProcessPoolWaitTests(ProcessPoolMixin, WaitTests, BaseTestCase):
pass


Expand Down Expand Up @@ -389,11 +397,11 @@ def test_duplicate_futures(self):
self.assertEqual(len(completed), 1)


class ThreadPoolAsCompletedTests(ThreadPoolMixin, AsCompletedTests, unittest.TestCase):
class ThreadPoolAsCompletedTests(ThreadPoolMixin, AsCompletedTests, BaseTestCase):
pass


class ProcessPoolAsCompletedTests(ProcessPoolMixin, AsCompletedTests, unittest.TestCase):
class ProcessPoolAsCompletedTests(ProcessPoolMixin, AsCompletedTests, BaseTestCase):
pass


Expand Down Expand Up @@ -464,7 +472,7 @@ def test_max_workers_negative(self):
self.executor_type(max_workers=number)


class ThreadPoolExecutorTest(ThreadPoolMixin, ExecutorTest, unittest.TestCase):
class ThreadPoolExecutorTest(ThreadPoolMixin, ExecutorTest, BaseTestCase):
def test_map_submits_without_iteration(self):
"""Tests verifying issue 11777."""
finished = []
Expand All @@ -481,7 +489,7 @@ def test_default_workers(self):
(os.cpu_count() or 1) * 5)


class ProcessPoolExecutorTest(ProcessPoolMixin, ExecutorTest, unittest.TestCase):
class ProcessPoolExecutorTest(ProcessPoolMixin, ExecutorTest, BaseTestCase):
def test_killed_child(self):
# When a child process is abruptly terminated, the whole pool gets
# "broken".
Expand Down Expand Up @@ -537,7 +545,7 @@ def test_traceback(self):
f1.getvalue())


class FutureTests(unittest.TestCase):
class FutureTests(BaseTestCase):
def test_done_callback_with_result(self):
callback_result = None
def fn(callback_future):
Expand Down