From 9d480d33159e2c9aa6e6db5afc0d8ba99a08f79d Mon Sep 17 00:00:00 2001 From: Grzegorz Grzywacz Date: Mon, 15 May 2017 01:35:40 +0200 Subject: [PATCH 1/4] bpo-30357 each test in test_thread waits until all spawn threads finish --- Lib/test/test_thread.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py index b46613876137b3..0c58300936b98b 100644 --- a/Lib/test/test_thread.py +++ b/Lib/test/test_thread.py @@ -32,6 +32,11 @@ def setUp(self): self.created = 0 self.running = 0 self.next_ident = 0 + self.thread_count = thread._count() + + def tearDown(self): + while self.thread_count != thread._count(): + time.sleep(0.01) class ThreadRunningTests(BasicThreadTest): From 7f5503fc9b29067777c55ff672f3b2a5d0cf3990 Mon Sep 17 00:00:00 2001 From: Grzegorz Grzywacz Date: Mon, 15 May 2017 11:13:45 +0200 Subject: [PATCH 2/4] bpo-30357 each test in test_thread waits until all spawn threads finish --- Lib/test/test_thread.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py index 0c58300936b98b..e1ea4d40d2cd94 100644 --- a/Lib/test/test_thread.py +++ b/Lib/test/test_thread.py @@ -32,11 +32,10 @@ def setUp(self): self.created = 0 self.running = 0 self.next_ident = 0 - self.thread_count = thread._count() + self._threads = test_support.threading_setup() def tearDown(self): - while self.thread_count != thread._count(): - time.sleep(0.01) + test_support.threading_cleanup(*self._threads) class ThreadRunningTests(BasicThreadTest): From f83a06f9a04f262ceafd74364313519e89641db8 Mon Sep 17 00:00:00 2001 From: Grzegorz Grzywacz Date: Mon, 15 May 2017 18:34:52 +0200 Subject: [PATCH 3/4] bpo-30357: test_thread now uses threading_cleanup() (#1592) test_thread: setUp() now uses support.threading_setup() and support.threading_cleanup() to wait until threads complete to avoid random side effects on following tests. Co-Authored-By: Victor Stinner --- Lib/test/test_thread.py | 6 +++--- Misc/ACKS | 1 + Misc/NEWS | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py index e1ea4d40d2cd94..759bdad8a23ccb 100644 --- a/Lib/test/test_thread.py +++ b/Lib/test/test_thread.py @@ -22,6 +22,7 @@ def verbose_print(arg): print arg + class BasicThreadTest(unittest.TestCase): def setUp(self): @@ -32,10 +33,9 @@ def setUp(self): self.created = 0 self.running = 0 self.next_ident = 0 - self._threads = test_support.threading_setup() - def tearDown(self): - test_support.threading_cleanup(*self._threads) + key = support.threading_setup() + self.addCleanup(support.threading_cleanup, *key) class ThreadRunningTests(BasicThreadTest): diff --git a/Misc/ACKS b/Misc/ACKS index 96cc90ed3644e5..01bcd3b834f162 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -507,6 +507,7 @@ Fabian Groffen Eric Groo Dag Gruneau Filip GruszczyƄski +Grzegorz Grzywacz Thomas Guettler Anuj Gupta Michael Guravage diff --git a/Misc/NEWS b/Misc/NEWS index 4c9f2d375e8911..56e882a0a513c8 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12106,6 +12106,10 @@ IDLE Tests ----- +- bpo-30357: test_thread: setUp() now uses support.threading_setup() and + support.threading_cleanup() to wait until threads complete to avoid + random side effects on following tests. Initial patch written by Grzegorz + Grzywacz. - Refactor test_logging to use unittest. From 596d8bd33296867d418c785f627d0ab14bd8a5f4 Mon Sep 17 00:00:00 2001 From: Grzegorz Grzywacz Date: Mon, 15 May 2017 18:53:15 +0200 Subject: [PATCH 4/4] bpo-30357: test_thread now uses threading_cleanup() (#1592) test_thread: setUp() now uses support.threading_setup() and support.threading_cleanup() to wait until threads complete to avoid random side effects on following tests. Co-Authored-By: Victor Stinner --- Lib/test/test_thread.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py index 759bdad8a23ccb..2f9abe078fc2ea 100644 --- a/Lib/test/test_thread.py +++ b/Lib/test/test_thread.py @@ -34,8 +34,8 @@ def setUp(self): self.running = 0 self.next_ident = 0 - key = support.threading_setup() - self.addCleanup(support.threading_cleanup, *key) + key = test_support.threading_setup() + self.addCleanup(test_support.threading_cleanup, *key) class ThreadRunningTests(BasicThreadTest):