summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-12-11 03:56:50 -0800
committerGitHub <noreply@github.com>2018-12-11 03:56:50 -0800
commit869e23e0af806ed3a10d0484827cb1b5f5cd5e5f (patch)
tree74576b3cc17e0410b6b5f84d7b9e3aebfb1d88b5
parent7d9f21950927e7c7fe69e5edeb06023a963c6f68 (diff)
downloadcpython-git-869e23e0af806ed3a10d0484827cb1b5f5cd5e5f.tar.gz
bpo-35426: Eliminate race condition in test_interprocess_signal (GH-11087)
The test only except SIGUSR1Exception inside wait_signal(), but the signal can be sent during subprocess_send_signal() call. (cherry picked from commit 2ab2afd387084ba38a37f5944fcb0675113b64dc) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
-rw-r--r--Lib/test/signalinterproctester.py40
1 files changed, 18 insertions, 22 deletions
diff --git a/Lib/test/signalinterproctester.py b/Lib/test/signalinterproctester.py
index 877be517c0..168b5da0f2 100644
--- a/Lib/test/signalinterproctester.py
+++ b/Lib/test/signalinterproctester.py
@@ -21,25 +21,19 @@ class InterProcessSignalTests(unittest.TestCase):
self.got_signals['SIGUSR1'] += 1
raise SIGUSR1Exception
- def wait_signal(self, child, signame, exc_class=None):
- try:
- if child is not None:
- # This wait should be interrupted by exc_class
- # (if set)
- child.wait()
-
- timeout = 10.0
- deadline = time.monotonic() + timeout
-
- while time.monotonic() < deadline:
- if self.got_signals[signame]:
- return
- signal.pause()
- except BaseException as exc:
- if exc_class is not None and isinstance(exc, exc_class):
- # got the expected exception
+ def wait_signal(self, child, signame):
+ if child is not None:
+ # This wait should be interrupted by exc_class
+ # (if set)
+ child.wait()
+
+ timeout = 10.0
+ deadline = time.monotonic() + timeout
+
+ while time.monotonic() < deadline:
+ if self.got_signals[signame]:
return
- raise
+ signal.pause()
self.fail('signal %s not received after %s seconds'
% (signame, timeout))
@@ -65,8 +59,9 @@ class InterProcessSignalTests(unittest.TestCase):
self.assertEqual(self.got_signals, {'SIGHUP': 1, 'SIGUSR1': 0,
'SIGALRM': 0})
- with self.subprocess_send_signal(pid, "SIGUSR1") as child:
- self.wait_signal(child, 'SIGUSR1', SIGUSR1Exception)
+ with self.assertRaises(SIGUSR1Exception):
+ with self.subprocess_send_signal(pid, "SIGUSR1") as child:
+ self.wait_signal(child, 'SIGUSR1')
self.assertEqual(self.got_signals, {'SIGHUP': 1, 'SIGUSR1': 1,
'SIGALRM': 0})
@@ -75,8 +70,9 @@ class InterProcessSignalTests(unittest.TestCase):
child.wait()
try:
- signal.alarm(1)
- self.wait_signal(None, 'SIGALRM', KeyboardInterrupt)
+ with self.assertRaises(KeyboardInterrupt):
+ signal.alarm(1)
+ self.wait_signal(None, 'SIGALRM')
self.assertEqual(self.got_signals, {'SIGHUP': 1, 'SIGUSR1': 1,
'SIGALRM': 0})
finally: