Skip to content

Commit ebac53a

Browse files
committed
Add more timeout values to test_poll_blocks_with_negative_ms
1 parent d47221a commit ebac53a

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

Lib/test/test_poll.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -208,31 +208,33 @@ def test_threaded_poll(self):
208208
@reap_threads
209209
def test_poll_blocks_with_negative_ms(self):
210210

211-
# GIVEN
211+
for timeout_ms in [None, -1, -1.0, -0.1, -1e-100]:
212212

213-
# Create two file descriptors. This will be used to unlock
214-
# the blocking call to poll.poll inside the thread
213+
# GIVEN
215214

216-
r, w = os.pipe()
217-
self.addCleanup(os.close, r)
218-
self.addCleanup(os.close, w)
215+
# Create two file descriptors. This will be used to unlock
216+
# the blocking call to poll.poll inside the thread
219217

220-
pollster = select.poll()
221-
pollster.register(r, select.POLLIN)
218+
r, w = os.pipe()
219+
self.addCleanup(os.close, r)
220+
self.addCleanup(os.close, w)
221+
222+
pollster = select.poll()
223+
pollster.register(r, select.POLLIN)
222224

223-
# WHEN
225+
# WHEN
224226

225-
poll_thread = threading.Thread(target=pollster.poll, args=(-1e-100,))
226-
poll_thread.start()
227-
poll_thread.join(timeout=0.1)
227+
poll_thread = threading.Thread(target=pollster.poll, args=(timeout_ms,))
228+
poll_thread.start()
229+
poll_thread.join(timeout=0.1)
228230

229-
# THEN
230-
self.assertTrue(poll_thread.is_alive())
231+
# THEN
232+
self.assertTrue(poll_thread.is_alive())
231233

232-
# Write to the pipe so pollster.poll unblocks and the thread ends.
233-
os.write(w, b'spam')
234-
poll_thread.join()
235-
self.assertFalse(poll_thread.is_alive())
234+
# Write to the pipe so pollster.poll unblocks and the thread ends.
235+
os.write(w, b'spam')
236+
poll_thread.join()
237+
self.assertFalse(poll_thread.is_alive())
236238

237239

238240

0 commit comments

Comments
 (0)