bpo-31234: Add support.join_thread() helper (#3587) · python/cpython@b9b6900
@@ -123,9 +123,7 @@ def line_terminator_check(self, term, server_chunk):
123123c.push(b"I'm not dead yet!" + term)
124124c.push(SERVER_QUIT)
125125asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
126-s.join(timeout=TIMEOUT)
127-if s.is_alive():
128-self.fail("join() timed out")
126+support.join_thread(s, timeout=TIMEOUT)
129127130128self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])
131129@@ -156,9 +154,7 @@ def numeric_terminator_check(self, termlen):
156154c.push(data)
157155c.push(SERVER_QUIT)
158156asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
159-s.join(timeout=TIMEOUT)
160-if s.is_alive():
161-self.fail("join() timed out")
157+support.join_thread(s, timeout=TIMEOUT)
162158163159self.assertEqual(c.contents, [data[:termlen]])
164160@@ -178,9 +174,7 @@ def test_none_terminator(self):
178174c.push(data)
179175c.push(SERVER_QUIT)
180176asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
181-s.join(timeout=TIMEOUT)
182-if s.is_alive():
183-self.fail("join() timed out")
177+support.join_thread(s, timeout=TIMEOUT)
184178185179self.assertEqual(c.contents, [])
186180self.assertEqual(c.buffer, data)
@@ -192,9 +186,7 @@ def test_simple_producer(self):
192186p = asynchat.simple_producer(data+SERVER_QUIT, buffer_size=8)
193187c.push_with_producer(p)
194188asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
195-s.join(timeout=TIMEOUT)
196-if s.is_alive():
197-self.fail("join() timed out")
189+support.join_thread(s, timeout=TIMEOUT)
198190199191self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])
200192@@ -204,9 +196,7 @@ def test_string_producer(self):
204196data = b"hello world\nI'm not dead yet!\n"
205197c.push_with_producer(data+SERVER_QUIT)
206198asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
207-s.join(timeout=TIMEOUT)
208-if s.is_alive():
209-self.fail("join() timed out")
199+support.join_thread(s, timeout=TIMEOUT)
210200211201self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])
212202@@ -217,9 +207,7 @@ def test_empty_line(self):
217207c.push(b"hello world\n\nI'm not dead yet!\n")
218208c.push(SERVER_QUIT)
219209asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
220-s.join(timeout=TIMEOUT)
221-if s.is_alive():
222-self.fail("join() timed out")
210+support.join_thread(s, timeout=TIMEOUT)
223211224212self.assertEqual(c.contents,
225213 [b"hello world", b"", b"I'm not dead yet!"])
@@ -238,9 +226,7 @@ def test_close_when_done(self):
238226# where the server echoes all of its data before we can check that it
239227# got any down below.
240228s.start_resend_event.set()
241-s.join(timeout=TIMEOUT)
242-if s.is_alive():
243-self.fail("join() timed out")
229+support.join_thread(s, timeout=TIMEOUT)
244230245231self.assertEqual(c.contents, [])
246232# the server might have been able to send a byte or two back, but this
@@ -261,7 +247,7 @@ def test_push(self):
261247self.assertRaises(TypeError, c.push, 'unicode')
262248c.push(SERVER_QUIT)
263249asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
264-s.join(timeout=TIMEOUT)
250+support.join_thread(s, timeout=TIMEOUT)
265251self.assertEqual(c.contents, [b'bytes', b'bytes', b'bytes'])
266252267253