mirror of
https://github.com/python/cpython.git
synced 2025-09-16 05:36:29 +00:00
Try to make test_signal less flaky. I still see some flakiness in
test_itimer_prof.
This commit is contained in:
parent
cb0f2ad0c2
commit
ab56131720
1 changed files with 24 additions and 6 deletions
|
@ -28,6 +28,15 @@ def exit_subprocess():
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
def ignoring_eintr(__func, *args, **kwargs):
|
||||||
|
try:
|
||||||
|
return __func(*args, **kwargs)
|
||||||
|
except IOError as e:
|
||||||
|
if e.errno != signal.EINTR:
|
||||||
|
raise
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class InterProcessSignalTests(unittest.TestCase):
|
class InterProcessSignalTests(unittest.TestCase):
|
||||||
MAX_DURATION = 20 # Entire test should last at most 20 sec.
|
MAX_DURATION = 20 # Entire test should last at most 20 sec.
|
||||||
|
|
||||||
|
@ -77,8 +86,11 @@ class InterProcessSignalTests(unittest.TestCase):
|
||||||
if test_support.verbose:
|
if test_support.verbose:
|
||||||
print "test runner's pid is", pid
|
print "test runner's pid is", pid
|
||||||
|
|
||||||
child = subprocess.Popen(['kill', '-HUP', str(pid)])
|
child = ignoring_eintr(subprocess.Popen, ['kill', '-HUP', str(pid)])
|
||||||
self.wait(child)
|
if child:
|
||||||
|
self.wait(child)
|
||||||
|
if not self.a_called:
|
||||||
|
time.sleep(1) # Give the signal time to be delivered.
|
||||||
self.assertTrue(self.a_called)
|
self.assertTrue(self.a_called)
|
||||||
self.assertFalse(self.b_called)
|
self.assertFalse(self.b_called)
|
||||||
self.a_called = False
|
self.a_called = False
|
||||||
|
@ -87,6 +99,7 @@ class InterProcessSignalTests(unittest.TestCase):
|
||||||
child = subprocess.Popen(['kill', '-USR1', str(pid)])
|
child = subprocess.Popen(['kill', '-USR1', str(pid)])
|
||||||
# This wait should be interrupted by the signal's exception.
|
# This wait should be interrupted by the signal's exception.
|
||||||
self.wait(child)
|
self.wait(child)
|
||||||
|
time.sleep(1) # Give the signal time to be delivered.
|
||||||
self.fail('HandlerBCalled exception not thrown')
|
self.fail('HandlerBCalled exception not thrown')
|
||||||
except HandlerBCalled:
|
except HandlerBCalled:
|
||||||
self.assertTrue(self.b_called)
|
self.assertTrue(self.b_called)
|
||||||
|
@ -94,8 +107,9 @@ class InterProcessSignalTests(unittest.TestCase):
|
||||||
if test_support.verbose:
|
if test_support.verbose:
|
||||||
print "HandlerBCalled exception caught"
|
print "HandlerBCalled exception caught"
|
||||||
|
|
||||||
child = subprocess.Popen(['kill', '-USR2', str(pid)])
|
child = ignoring_eintr(subprocess.Popen, ['kill', '-USR2', str(pid)])
|
||||||
self.wait(child) # Nothing should happen.
|
if child:
|
||||||
|
self.wait(child) # Nothing should happen.
|
||||||
|
|
||||||
try:
|
try:
|
||||||
signal.alarm(1)
|
signal.alarm(1)
|
||||||
|
@ -103,14 +117,18 @@ class InterProcessSignalTests(unittest.TestCase):
|
||||||
# since alarm is going to raise a KeyboardException, which
|
# since alarm is going to raise a KeyboardException, which
|
||||||
# will skip the call.
|
# will skip the call.
|
||||||
signal.pause()
|
signal.pause()
|
||||||
|
# But if another signal arrives before the alarm, pause
|
||||||
|
# may return early.
|
||||||
|
time.sleep(1)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
if test_support.verbose:
|
if test_support.verbose:
|
||||||
print "KeyboardInterrupt (the alarm() went off)"
|
print "KeyboardInterrupt (the alarm() went off)"
|
||||||
except:
|
except:
|
||||||
self.fail('Some other exception woke us from pause: %s' %
|
self.fail("Some other exception woke us from pause: %s" %
|
||||||
traceback.format_exc())
|
traceback.format_exc())
|
||||||
else:
|
else:
|
||||||
self.fail('pause returned of its own accord')
|
self.fail("pause returned of its own accord, and the signal"
|
||||||
|
" didn't arrive after another second.")
|
||||||
|
|
||||||
def test_main(self):
|
def test_main(self):
|
||||||
# This function spawns a child process to insulate the main
|
# This function spawns a child process to insulate the main
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue