summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_signal.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-08-27 10:59:44 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-08-27 10:59:44 (GMT)
commit3822760f2d6ce4ab61daab2ab5ebc83bea839e92 (patch)
tree849139257c073fd7bf91252c94af2ea165b2fc24 /Lib/test/test_signal.py
parent86cc17e69ebc002318d62501e914dc9bb394e503 (diff)
downloadcpython-3822760f2d6ce4ab61daab2ab5ebc83bea839e92.zip
cpython-3822760f2d6ce4ab61daab2ab5ebc83bea839e92.tar.gz
cpython-3822760f2d6ce4ab61daab2ab5ebc83bea839e92.tar.bz2
Issue #22042: signal.set_wakeup_fd(fd) now raises an exception if the file
descriptor is in blocking mode.
Diffstat (limited to 'Lib/test/test_signal.py')
-rw-r--r--Lib/test/test_signal.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py
index 57b0d86..812bd90 100644
--- a/Lib/test/test_signal.py
+++ b/Lib/test/test_signal.py
@@ -271,6 +271,9 @@ class WakeupFDTests(unittest.TestCase):
self.addCleanup(os.close, r2)
self.addCleanup(os.close, w2)
+ os.set_blocking(w1, False)
+ os.set_blocking(w2, False)
+
signal.set_wakeup_fd(w1)
self.assertEqual(signal.set_wakeup_fd(w2), w1)
self.assertEqual(signal.set_wakeup_fd(-1), w2)
@@ -279,10 +282,12 @@ class WakeupFDTests(unittest.TestCase):
def test_set_wakeup_fd_socket_result(self):
sock1 = socket.socket()
self.addCleanup(sock1.close)
+ sock1.setblocking(False)
fd1 = sock1.fileno()
sock2 = socket.socket()
self.addCleanup(sock2.close)
+ sock2.setblocking(False)
fd2 = sock2.fileno()
signal.set_wakeup_fd(fd1)
@@ -290,6 +295,26 @@ class WakeupFDTests(unittest.TestCase):
self.assertEqual(signal.set_wakeup_fd(-1), fd2)
self.assertEqual(signal.set_wakeup_fd(-1), -1)
+ # On Windows, files are always blocking and Windows does not provide a
+ # function to test if a socket is in non-blocking mode.
+ @unittest.skipIf(sys.platform == "win32", "tests specific to POSIX")
+ def test_set_wakeup_fd_blocking(self):
+ rfd, wfd = os.pipe()
+ self.addCleanup(os.close, rfd)
+ self.addCleanup(os.close, wfd)
+
+ # fd must be non-blocking
+ os.set_blocking(wfd, True)
+ with self.assertRaises(ValueError) as cm:
+ signal.set_wakeup_fd(wfd)
+ self.assertEqual(str(cm.exception),
+ "the fd %s must be in non-blocking mode" % wfd)
+
+ # non-blocking is ok
+ os.set_blocking(wfd, False)
+ signal.set_wakeup_fd(wfd)
+ signal.set_wakeup_fd(-1)
+
@unittest.skipIf(sys.platform == "win32", "Not valid on Windows")
class WakeupSignalTests(unittest.TestCase):