aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_poll.py
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2017-10-17 15:14:41 +0100
committerSerhiy Storchaka <storchaka@gmail.com>2017-10-17 17:14:41 +0300
commit2c15b29aea5d6b9c61aa42d2c24a07ff1edb4b46 (patch)
treeb6b9f24a447144147ddd1959f90016106c077c05 /Lib/test/test_poll.py
parent552be9d7e64f91b8e4ba5b29cd5dcc442d56f92c (diff)
downloadcpython-2c15b29aea5d6b9c61aa42d2c24a07ff1edb4b46.tar.gz
cpython-2c15b29aea5d6b9c61aa42d2c24a07ff1edb4b46.zip
bpo-31786: Make functions in the select module blocking when timeout is a small negative value. (#4003)
Diffstat (limited to 'Lib/test/test_poll.py')
-rw-r--r--Lib/test/test_poll.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_poll.py b/Lib/test/test_poll.py
index 16c2d2e123b..028dd2d08a3 100644
--- a/Lib/test/test_poll.py
+++ b/Lib/test/test_poll.py
@@ -204,6 +204,28 @@ class PollTests(unittest.TestCase):
os.write(w, b'spam')
t.join()
+ @unittest.skipUnless(threading, 'Threading required for this test.')
+ @reap_threads
+ def test_poll_blocks_with_negative_ms(self):
+ for timeout_ms in [None, -1, -1.0, -0.1, -1e-100]:
+ # Create two file descriptors. This will be used to unlock
+ # the blocking call to poll.poll inside the thread
+ r, w = os.pipe()
+ pollster = select.poll()
+ pollster.register(r, select.POLLIN)
+
+ poll_thread = threading.Thread(target=pollster.poll, args=(timeout_ms,))
+ poll_thread.start()
+ poll_thread.join(timeout=0.1)
+ self.assertTrue(poll_thread.is_alive())
+
+ # Write to the pipe so pollster.poll unblocks and the thread ends.
+ os.write(w, b'spam')
+ poll_thread.join()
+ self.assertFalse(poll_thread.is_alive())
+ os.close(r)
+ os.close(w)
+
def test_main():
run_unittest(PollTests)