Commit 8150492f authored by Gregory P. Smith's avatar Gregory P. Smith

Speed up test_io by >2x by reducing the sleep time using setitimer instead of

alarm for the signal tests.
parent 7349eb27
...@@ -2868,7 +2868,7 @@ class SignalsTest(unittest.TestCase): ...@@ -2868,7 +2868,7 @@ class SignalsTest(unittest.TestCase):
try: try:
wio = self.io.open(w, **fdopen_kwargs) wio = self.io.open(w, **fdopen_kwargs)
t.start() t.start()
signal.alarm(1) signal.setitimer(signal.ITIMER_REAL, 0.1)
# Fill the pipe enough that the write will be blocking. # Fill the pipe enough that the write will be blocking.
# It will be interrupted by the timer armed above. Since the # It will be interrupted by the timer armed above. Since the
# other thread has read one byte, the low-level write will # other thread has read one byte, the low-level write will
...@@ -2912,7 +2912,7 @@ class SignalsTest(unittest.TestCase): ...@@ -2912,7 +2912,7 @@ class SignalsTest(unittest.TestCase):
r, w = os.pipe() r, w = os.pipe()
wio = self.io.open(w, **fdopen_kwargs) wio = self.io.open(w, **fdopen_kwargs)
try: try:
signal.alarm(1) signal.setitimer(signal.ITIMER_REAL, 0.1)
# Either the reentrant call to wio.write() fails with RuntimeError, # Either the reentrant call to wio.write() fails with RuntimeError,
# or the signal handler raises ZeroDivisionError. # or the signal handler raises ZeroDivisionError.
with self.assertRaises((ZeroDivisionError, RuntimeError)) as cm: with self.assertRaises((ZeroDivisionError, RuntimeError)) as cm:
...@@ -2947,7 +2947,7 @@ class SignalsTest(unittest.TestCase): ...@@ -2947,7 +2947,7 @@ class SignalsTest(unittest.TestCase):
try: try:
rio = self.io.open(r, **fdopen_kwargs) rio = self.io.open(r, **fdopen_kwargs)
os.write(w, b"foo") os.write(w, b"foo")
signal.alarm(1) signal.setitimer(signal.ITIMER_REAL, 0.1)
# Expected behaviour: # Expected behaviour:
# - first raw read() returns partial b"foo" # - first raw read() returns partial b"foo"
# - second raw read() returns EINTR # - second raw read() returns EINTR
...@@ -2991,13 +2991,13 @@ class SignalsTest(unittest.TestCase): ...@@ -2991,13 +2991,13 @@ class SignalsTest(unittest.TestCase):
t.daemon = True t.daemon = True
def alarm1(sig, frame): def alarm1(sig, frame):
signal.signal(signal.SIGALRM, alarm2) signal.signal(signal.SIGALRM, alarm2)
signal.alarm(1) signal.setitimer(signal.ITIMER_REAL, 0.1)
def alarm2(sig, frame): def alarm2(sig, frame):
t.start() t.start()
signal.signal(signal.SIGALRM, alarm1) signal.signal(signal.SIGALRM, alarm1)
try: try:
wio = self.io.open(w, **fdopen_kwargs) wio = self.io.open(w, **fdopen_kwargs)
signal.alarm(1) signal.setitimer(signal.ITIMER_REAL, 0.1)
# Expected behaviour: # Expected behaviour:
# - first raw write() is partial (because of the limited pipe buffer # - first raw write() is partial (because of the limited pipe buffer
# and the first alarm) # and the first alarm)
......
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