summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-03-13 18:16:03 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-03-13 18:16:03 (GMT)
commitf74dee4b88977d696285049f8a4d86026a98090f (patch)
tree6b0397b2525cfa274757f549675d55ec851eef71 /Lib/test
parent279755a165ba64988c9789d27aa7221058193ff2 (diff)
parentd3cccd2a60914caef40ada0c16e90da4fc4270b3 (diff)
downloadcpython-f74dee4b88977d696285049f8a4d86026a98090f.zip
cpython-f74dee4b88977d696285049f8a4d86026a98090f.tar.gz
cpython-f74dee4b88977d696285049f8a4d86026a98090f.tar.bz2
Merge commit for #11233
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_threadsignals.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/Lib/test/test_threadsignals.py b/Lib/test/test_threadsignals.py
index 2462307..46e405a 100644
--- a/Lib/test/test_threadsignals.py
+++ b/Lib/test/test_threadsignals.py
@@ -73,18 +73,29 @@ class ThreadSignals(unittest.TestCase):
def test_lock_acquire_interruption(self):
# Mimic receiving a SIGINT (KeyboardInterrupt) with SIGALRM while stuck
# in a deadlock.
+ # XXX this test can fail when the legacy (non-semaphore) implementation
+ # of locks is used in thread_pthread.h, see issue #11223.
oldalrm = signal.signal(signal.SIGALRM, self.alarm_interrupt)
try:
lock = thread.allocate_lock()
lock.acquire()
signal.alarm(1)
- self.assertRaises(KeyboardInterrupt, lock.acquire)
+ t1 = time.time()
+ self.assertRaises(KeyboardInterrupt, lock.acquire, timeout=5)
+ dt = time.time() - t1
+ # Checking that KeyboardInterrupt was raised is not sufficient.
+ # We want to assert that lock.acquire() was interrupted because
+ # of the signal, not that the signal handler was called immediately
+ # after timeout return of lock.acquire() (which can fool assertRaises).
+ self.assertLess(dt, 3.0)
finally:
signal.signal(signal.SIGALRM, oldalrm)
def test_rlock_acquire_interruption(self):
# Mimic receiving a SIGINT (KeyboardInterrupt) with SIGALRM while stuck
# in a deadlock.
+ # XXX this test can fail when the legacy (non-semaphore) implementation
+ # of locks is used in thread_pthread.h, see issue #11223.
oldalrm = signal.signal(signal.SIGALRM, self.alarm_interrupt)
try:
rlock = thread.RLock()
@@ -98,7 +109,11 @@ class ThreadSignals(unittest.TestCase):
rlock.release()
time.sleep(0.01)
signal.alarm(1)
- self.assertRaises(KeyboardInterrupt, rlock.acquire)
+ t1 = time.time()
+ self.assertRaises(KeyboardInterrupt, rlock.acquire, timeout=5)
+ dt = time.time() - t1
+ # See rationale above in test_lock_acquire_interruption
+ self.assertLess(dt, 3.0)
finally:
signal.signal(signal.SIGALRM, oldalrm)