summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-11-21 15:33:13 (GMT)
committerGitHub <noreply@github.com>2018-11-21 15:33:13 (GMT)
commitaac1f81eef971876ba5b1673db9ce6620311c469 (patch)
tree8cc2935e2226572bc81bb28a6722d978acedf7ef
parent361e8683e7340c600b22f4a514b81448ccec66dc (diff)
downloadcpython-aac1f81eef971876ba5b1673db9ce6620311c469.zip
cpython-aac1f81eef971876ba5b1673db9ce6620311c469.tar.gz
cpython-aac1f81eef971876ba5b1673db9ce6620311c469.tar.bz2
bpo-35189: Fix eintr_tester.py (GH-10637)
Call setitimer() before each test method, instead of once per test case, to ensure that signals are sent in each test method. Previously, only the first method of a testcase class got signals. Changes: * Replace setUpClass() with setUp() and replace tearDownClass() with tearDown(). * tearDown() now ensures that at least one signal has been sent. * Replace support.run_unittest() with unittest.main() which has a nicer CLI and automatically discover test cases.
-rw-r--r--Lib/test/eintrdata/eintr_tester.py40
1 files changed, 18 insertions, 22 deletions
diff --git a/Lib/test/eintrdata/eintr_tester.py b/Lib/test/eintrdata/eintr_tester.py
index 1caeafe..18d9d84 100644
--- a/Lib/test/eintrdata/eintr_tester.py
+++ b/Lib/test/eintrdata/eintr_tester.py
@@ -44,27 +44,32 @@ class EINTRBaseTest(unittest.TestCase):
# sleep_time > signal_period
sleep_time = 0.2
- @classmethod
- def setUpClass(cls):
- cls.orig_handler = signal.signal(signal.SIGALRM, lambda *args: None)
- signal.setitimer(signal.ITIMER_REAL, cls.signal_delay,
- cls.signal_period)
+ def sighandler(self, signum, frame):
+ self.signals += 1
- # Issue #25277: Use faulthandler to try to debug a hang on FreeBSD
+ def setUp(self):
+ self.signals = 0
+ self.orig_handler = signal.signal(signal.SIGALRM, self.sighandler)
+ signal.setitimer(signal.ITIMER_REAL, self.signal_delay,
+ self.signal_period)
+
+ # Use faulthandler as watchdog to debug when a test hangs
+ # (timeout of 10 minutes)
if hasattr(faulthandler, 'dump_traceback_later'):
faulthandler.dump_traceback_later(10 * 60, exit=True,
file=sys.__stderr__)
- @classmethod
- def stop_alarm(cls):
+ @staticmethod
+ def stop_alarm():
signal.setitimer(signal.ITIMER_REAL, 0, 0)
- @classmethod
- def tearDownClass(cls):
- cls.stop_alarm()
- signal.signal(signal.SIGALRM, cls.orig_handler)
+ def tearDown(self):
+ self.stop_alarm()
+ signal.signal(signal.SIGALRM, self.orig_handler)
if hasattr(faulthandler, 'cancel_dump_traceback_later'):
faulthandler.cancel_dump_traceback_later()
+ # make sure that at least one signal has been received
+ self.assertGreater(self.signals, 0)
def subprocess(self, *args, **kw):
cmd_args = (sys.executable, '-c') + args
@@ -481,14 +486,5 @@ class SelectEINTRTest(EINTRBaseTest):
self.assertGreaterEqual(dt, self.sleep_time)
-def test_main():
- support.run_unittest(
- OSEINTRTest,
- SocketEINTRTest,
- TimeEINTRTest,
- SignalEINTRTest,
- SelectEINTRTest)
-
-
if __name__ == "__main__":
- test_main()
+ unittest.main()