Kaydet (Commit) c98efe05 authored tarafından Antoine Pitrou's avatar Antoine Pitrou

Issue #7270: Add some dedicated unit tests for multi-thread synchronization

primitives such as Lock, RLock, Condition, Event and Semaphore.
üst 17f0f692
This diff is collapsed.
...@@ -6,6 +6,7 @@ import thread ...@@ -6,6 +6,7 @@ import thread
import time import time
import weakref import weakref
from test import lock_tests
NUMTASKS = 10 NUMTASKS = 10
NUMTRIPS = 3 NUMTRIPS = 3
...@@ -191,8 +192,12 @@ class BarrierTest(BasicThreadTest): ...@@ -191,8 +192,12 @@ class BarrierTest(BasicThreadTest):
self.done_mutex.release() self.done_mutex.release()
class LockTests(lock_tests.LockTests):
locktype = thread.allocate_lock
def test_main(): def test_main():
test_support.run_unittest(ThreadRunningTests, BarrierTest) test_support.run_unittest(ThreadRunningTests, BarrierTest, LockTests)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()
...@@ -11,6 +11,8 @@ import time ...@@ -11,6 +11,8 @@ import time
import unittest import unittest
import weakref import weakref
from test import lock_tests
# A trivial mutable counter. # A trivial mutable counter.
class Counter(object): class Counter(object):
def __init__(self): def __init__(self):
...@@ -482,22 +484,6 @@ class ThreadingExceptionTests(BaseTestCase): ...@@ -482,22 +484,6 @@ class ThreadingExceptionTests(BaseTestCase):
thread.start() thread.start()
self.assertRaises(RuntimeError, thread.start) self.assertRaises(RuntimeError, thread.start)
def test_releasing_unacquired_rlock(self):
rlock = threading.RLock()
self.assertRaises(RuntimeError, rlock.release)
def test_waiting_on_unacquired_condition(self):
cond = threading.Condition()
self.assertRaises(RuntimeError, cond.wait)
def test_notify_on_unacquired_condition(self):
cond = threading.Condition()
self.assertRaises(RuntimeError, cond.notify)
def test_semaphore_with_negative_value(self):
self.assertRaises(ValueError, threading.Semaphore, value = -1)
self.assertRaises(ValueError, threading.Semaphore, value = -sys.maxint)
def test_joining_current_thread(self): def test_joining_current_thread(self):
current_thread = threading.current_thread() current_thread = threading.current_thread()
self.assertRaises(RuntimeError, current_thread.join); self.assertRaises(RuntimeError, current_thread.join);
...@@ -512,8 +498,34 @@ class ThreadingExceptionTests(BaseTestCase): ...@@ -512,8 +498,34 @@ class ThreadingExceptionTests(BaseTestCase):
self.assertRaises(RuntimeError, setattr, thread, "daemon", True) self.assertRaises(RuntimeError, setattr, thread, "daemon", True)
class LockTests(lock_tests.LockTests):
locktype = staticmethod(threading.Lock)
class RLockTests(lock_tests.RLockTests):
locktype = staticmethod(threading.RLock)
class EventTests(lock_tests.EventTests):
eventtype = staticmethod(threading.Event)
class ConditionAsRLockTests(lock_tests.RLockTests):
# An Condition uses an RLock by default and exports its API.
locktype = staticmethod(threading.Condition)
class ConditionTests(lock_tests.ConditionTests):
condtype = staticmethod(threading.Condition)
class SemaphoreTests(lock_tests.SemaphoreTests):
semtype = staticmethod(threading.Semaphore)
class BoundedSemaphoreTests(lock_tests.BoundedSemaphoreTests):
semtype = staticmethod(threading.BoundedSemaphore)
def test_main(): def test_main():
test.test_support.run_unittest(ThreadTests, test.test_support.run_unittest(LockTests, RLockTests, EventTests,
ConditionAsRLockTests, ConditionTests,
SemaphoreTests, BoundedSemaphoreTests,
ThreadTests,
ThreadJoinOnShutdown, ThreadJoinOnShutdown,
ThreadingExceptionTests, ThreadingExceptionTests,
) )
......
...@@ -1551,6 +1551,9 @@ Extension Modules ...@@ -1551,6 +1551,9 @@ Extension Modules
Tests Tests
----- -----
- Issue #7270: Add some dedicated unit tests for multi-thread synchronization
primitives such as Lock, RLock, Condition, Event and Semaphore.
- Issue #7222: Make thread "reaping" more reliable so that reference - Issue #7222: Make thread "reaping" more reliable so that reference
leak-chasing test runs give sensible results. The previous method of leak-chasing test runs give sensible results. The previous method of
reaping threads could return successfully while some Thread objects were reaping threads could return successfully while some Thread objects were
......
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