summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2017-10-18 08:12:47 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-10-18 08:12:47 (GMT)
commit95602b368b87da3702a0f340ded2a23e823bb104 (patch)
tree48698f6120f2e0ee60d3df01a3fefc9531d3473d /Lib/test
parent178148025494c4058571831fb11fc8eeff8b7365 (diff)
downloadcpython-95602b368b87da3702a0f340ded2a23e823bb104.zip
cpython-95602b368b87da3702a0f340ded2a23e823bb104.tar.gz
cpython-95602b368b87da3702a0f340ded2a23e823bb104.tar.bz2
[3.6] bpo-31786: Make functions in the select module blocking when timeout is a small negative value. (GH-4003). (#4022)
(cherry picked from commit 2c15b29aea5d6b9c61aa42d2c24a07ff1edb4b46)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_poll.py22
-rw-r--r--Lib/test/test_time.py3
2 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_poll.py b/Lib/test/test_poll.py
index 6a2bf6e..2a39360 100644
--- a/Lib/test/test_poll.py
+++ b/Lib/test/test_poll.py
@@ -208,6 +208,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)
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
index 7093fc6..5b6e58f 100644
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -36,6 +36,8 @@ class _PyTime(enum.IntEnum):
ROUND_CEILING = 1
# Round to nearest with ties going to nearest even integer
ROUND_HALF_EVEN = 2
+ # Round away from zero
+ ROUND_UP = 3
# Rounding modes supported by PyTime
ROUNDING_MODES = (
@@ -43,6 +45,7 @@ ROUNDING_MODES = (
(_PyTime.ROUND_FLOOR, decimal.ROUND_FLOOR),
(_PyTime.ROUND_CEILING, decimal.ROUND_CEILING),
(_PyTime.ROUND_HALF_EVEN, decimal.ROUND_HALF_EVEN),
+ (_PyTime.ROUND_UP, decimal.ROUND_UP),
)