mirror of
https://github.com/python/cpython.git
synced 2025-10-03 05:35:59 +00:00
bpo-31234: Join threads in tests (#3572)
Call thread.join() on threads to prevent the "dangling threads" warning.
This commit is contained in:
parent
1bbd482bcf
commit
18e95b4176
4 changed files with 15 additions and 3 deletions
|
@ -772,6 +772,7 @@ class FutureTests(BaseTestCase):
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
self.assertEqual(f1.result(timeout=5), 42)
|
self.assertEqual(f1.result(timeout=5), 42)
|
||||||
|
t.join()
|
||||||
|
|
||||||
def test_result_with_cancel(self):
|
def test_result_with_cancel(self):
|
||||||
# TODO(brian@sweetapp.com): This test is timing dependent.
|
# TODO(brian@sweetapp.com): This test is timing dependent.
|
||||||
|
@ -785,6 +786,7 @@ class FutureTests(BaseTestCase):
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
self.assertRaises(futures.CancelledError, f1.result, timeout=5)
|
self.assertRaises(futures.CancelledError, f1.result, timeout=5)
|
||||||
|
t.join()
|
||||||
|
|
||||||
def test_exception_with_timeout(self):
|
def test_exception_with_timeout(self):
|
||||||
self.assertRaises(futures.TimeoutError,
|
self.assertRaises(futures.TimeoutError,
|
||||||
|
@ -813,6 +815,7 @@ class FutureTests(BaseTestCase):
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
self.assertTrue(isinstance(f1.exception(timeout=5), OSError))
|
self.assertTrue(isinstance(f1.exception(timeout=5), OSError))
|
||||||
|
t.join()
|
||||||
|
|
||||||
@test.support.reap_threads
|
@test.support.reap_threads
|
||||||
def test_main():
|
def test_main():
|
||||||
|
|
|
@ -1618,6 +1618,9 @@ class ThreadingTest(unittest.TestCase):
|
||||||
for sig in Signals[self.decimal]:
|
for sig in Signals[self.decimal]:
|
||||||
self.assertFalse(DefaultContext.flags[sig])
|
self.assertFalse(DefaultContext.flags[sig])
|
||||||
|
|
||||||
|
th1.join()
|
||||||
|
th2.join()
|
||||||
|
|
||||||
DefaultContext.prec = save_prec
|
DefaultContext.prec = save_prec
|
||||||
DefaultContext.Emax = save_emax
|
DefaultContext.Emax = save_emax
|
||||||
DefaultContext.Emin = save_emin
|
DefaultContext.Emin = save_emin
|
||||||
|
|
|
@ -611,7 +611,9 @@ class TooLongLineTests(unittest.TestCase):
|
||||||
self.sock.settimeout(15)
|
self.sock.settimeout(15)
|
||||||
self.port = support.bind_port(self.sock)
|
self.port = support.bind_port(self.sock)
|
||||||
servargs = (self.evt, self.respdata, self.sock)
|
servargs = (self.evt, self.respdata, self.sock)
|
||||||
threading.Thread(target=server, args=servargs).start()
|
thread = threading.Thread(target=server, args=servargs)
|
||||||
|
thread.start()
|
||||||
|
self.addCleanup(thread.join)
|
||||||
self.evt.wait()
|
self.evt.wait()
|
||||||
self.evt.clear()
|
self.evt.clear()
|
||||||
|
|
||||||
|
|
|
@ -755,7 +755,9 @@ class BaseServerTestCase(unittest.TestCase):
|
||||||
self.evt = threading.Event()
|
self.evt = threading.Event()
|
||||||
# start server thread to handle requests
|
# start server thread to handle requests
|
||||||
serv_args = (self.evt, self.request_count, self.requestHandler)
|
serv_args = (self.evt, self.request_count, self.requestHandler)
|
||||||
threading.Thread(target=self.threadFunc, args=serv_args).start()
|
thread = threading.Thread(target=self.threadFunc, args=serv_args)
|
||||||
|
thread.start()
|
||||||
|
self.addCleanup(thread.join)
|
||||||
|
|
||||||
# wait for the server to be ready
|
# wait for the server to be ready
|
||||||
self.evt.wait()
|
self.evt.wait()
|
||||||
|
@ -1206,7 +1208,9 @@ class FailingServerTestCase(unittest.TestCase):
|
||||||
self.evt = threading.Event()
|
self.evt = threading.Event()
|
||||||
# start server thread to handle requests
|
# start server thread to handle requests
|
||||||
serv_args = (self.evt, 1)
|
serv_args = (self.evt, 1)
|
||||||
threading.Thread(target=http_server, args=serv_args).start()
|
thread = threading.Thread(target=http_server, args=serv_args)
|
||||||
|
thread.start()
|
||||||
|
self.addCleanup(thread.join)
|
||||||
|
|
||||||
# wait for the server to be ready
|
# wait for the server to be ready
|
||||||
self.evt.wait()
|
self.evt.wait()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue