Commit e40b3aab authored by Victor Stinner's avatar Victor Stinner

Issue #12469: Run "wakeup" signal tests in subprocess to run the test in a

fresh process with only one thread and to not change signal handling of the
parent process.
parent cd1aa0d5
...@@ -11,7 +11,7 @@ import traceback ...@@ -11,7 +11,7 @@ import traceback
import unittest import unittest
from test import support from test import support
from contextlib import closing from contextlib import closing
from test.script_helper import spawn_python from test.script_helper import assert_python_ok, spawn_python
if sys.platform in ('os2', 'riscos'): if sys.platform in ('os2', 'riscos'):
raise unittest.SkipTest("Can't test signal on %s" % sys.platform) raise unittest.SkipTest("Can't test signal on %s" % sys.platform)
...@@ -233,49 +233,80 @@ class WindowsSignalTests(unittest.TestCase): ...@@ -233,49 +233,80 @@ class WindowsSignalTests(unittest.TestCase):
@unittest.skipIf(sys.platform == "win32", "Not valid on Windows") @unittest.skipIf(sys.platform == "win32", "Not valid on Windows")
class WakeupSignalTests(unittest.TestCase): class WakeupSignalTests(unittest.TestCase):
TIMEOUT_FULL = 10 def check_wakeup(self, test_body):
TIMEOUT_HALF = 5 # use a subprocess to have only one thread and to not change signal
# handling of the parent process
code = """if 1:
import fcntl
import os
import signal
def handler(signum, frame):
pass
{}
signal.signal(signal.SIGALRM, handler)
read, write = os.pipe()
flags = fcntl.fcntl(write, fcntl.F_GETFL, 0)
flags = flags | os.O_NONBLOCK
fcntl.fcntl(write, fcntl.F_SETFL, flags)
signal.set_wakeup_fd(write)
test()
os.close(read)
os.close(write)
""".format(test_body)
assert_python_ok('-c', code)
def test_wakeup_fd_early(self): def test_wakeup_fd_early(self):
import select self.check_wakeup("""def test():
import select
signal.alarm(1) import time
before_time = time.time()
# We attempt to get a signal during the sleep,
# before select is called
time.sleep(self.TIMEOUT_FULL)
mid_time = time.time()
self.assertTrue(mid_time - before_time < self.TIMEOUT_HALF)
select.select([self.read], [], [], self.TIMEOUT_FULL)
after_time = time.time()
self.assertTrue(after_time - mid_time < self.TIMEOUT_HALF)
def test_wakeup_fd_during(self): TIMEOUT_FULL = 10
import select TIMEOUT_HALF = 5
signal.alarm(1) signal.alarm(1)
before_time = time.time() before_time = time.time()
# We attempt to get a signal during the select call # We attempt to get a signal during the sleep,
self.assertRaises(select.error, select.select, # before select is called
[self.read], [], [], self.TIMEOUT_FULL) time.sleep(TIMEOUT_FULL)
after_time = time.time() mid_time = time.time()
self.assertTrue(after_time - before_time < self.TIMEOUT_HALF) dt = mid_time - before_time
if dt >= TIMEOUT_HALF:
raise Exception("%s >= %s" % (dt, TIMEOUT_HALF))
select.select([read], [], [], TIMEOUT_FULL)
after_time = time.time()
dt = after_time - mid_time
if dt >= TIMEOUT_HALF:
raise Exception("%s >= %s" % (dt, TIMEOUT_HALF))
""")
def setUp(self): def test_wakeup_fd_during(self):
import fcntl self.check_wakeup("""def test():
import select
import time
self.alrm = signal.signal(signal.SIGALRM, lambda x,y:None) TIMEOUT_FULL = 10
self.read, self.write = os.pipe() TIMEOUT_HALF = 5
flags = fcntl.fcntl(self.write, fcntl.F_GETFL, 0)
flags = flags | os.O_NONBLOCK
fcntl.fcntl(self.write, fcntl.F_SETFL, flags)
self.old_wakeup = signal.set_wakeup_fd(self.write)
def tearDown(self): signal.alarm(1)
signal.set_wakeup_fd(self.old_wakeup) before_time = time.time()
os.close(self.read) # We attempt to get a signal during the select call
os.close(self.write) try:
signal.signal(signal.SIGALRM, self.alrm) select.select([read], [], [], TIMEOUT_FULL)
except select.error:
pass
else:
raise Exception("select.error not raised")
after_time = time.time()
dt = after_time - before_time
if dt >= TIMEOUT_HALF:
raise Exception("%s >= %s" % (dt, TIMEOUT_HALF))
""")
@unittest.skipIf(sys.platform == "win32", "Not valid on Windows") @unittest.skipIf(sys.platform == "win32", "Not valid on Windows")
class SiginterruptTest(unittest.TestCase): class SiginterruptTest(unittest.TestCase):
......
...@@ -38,6 +38,10 @@ C-API ...@@ -38,6 +38,10 @@ C-API
Tests Tests
----- -----
- Issue #12469: Run "wakeup" signal tests in subprocess to run the test in a
fresh process with only one thread and to not change signal handling of the
parent process.
- Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run - Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
test_tk or test_ttk_guionly under a username that is not currently logged test_tk or test_ttk_guionly under a username that is not currently logged
in to the console windowserver (as may be the case under buildbot or ssh). in to the console windowserver (as may be the case under buildbot or ssh).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment