[pypy-commit] pypy default: move slow test to its own class and skip it
mattip
pypy.commits at gmail.com
Fri Dec 6 09:35:15 EST 2019
Author: Matti Picus <matti.picus at gmail.com>
Branch:
Changeset: r98238:9c171d039841
Date: 2019-12-06 16:30 +0200
http://bitbucket.org/pypy/pypy/changeset/9c171d039841/
Log: move slow test to its own class and skip it
diff --git a/pypy/module/thread/test/test_thread.py b/pypy/module/thread/test/test_thread.py
--- a/pypy/module/thread/test/test_thread.py
+++ b/pypy/module/thread/test/test_thread.py
@@ -3,36 +3,6 @@
class AppTestThread(GenericTestThread):
- def setup_class(cls):
- GenericTestThread.setup_class.im_func(cls)
- # if we cannot start more than, say, 1000 threads on this OS, then
- # we can check that we get the proper error at app-level
- space = cls.space
- lock = thread.allocate_lock()
- lock.acquire()
- def f():
- lock.acquire()
- lock.release()
- start = thread._count()
- try:
- try:
- for i in range(1000):
- thread.start_new_thread(f, ())
- finally:
- lock.release()
- except (thread.error, MemoryError):
- cls.w_can_start_many_threads = space.wrap(False)
- else:
- cls.w_can_start_many_threads = space.wrap(True)
- # wait a bit to allow all threads to finish now
- remaining = thread._count()
- retries = 0
- while remaining > start:
- retries += 1
- if retries == 200:
- raise Exception("the test's threads don't stop!")
- time.sleep(0.2)
- remaining = thread._count()
def test_start_new_thread(self):
import thread
@@ -189,35 +159,6 @@
assert done # see stderr for failures in threads
assert sorted(lst) == range(120)
- def test_many_threads(self):
- import thread, time
- if self.can_start_many_threads:
- skip("this OS supports too many threads to check (> 1000)")
- lock = thread.allocate_lock()
- lock.acquire()
- count = [0]
- def f():
- count[0] += 1
- lock.acquire()
- lock.release()
- count[0] -= 1
- try:
- try:
- for i in range(1000):
- thread.start_new_thread(f, ())
- finally:
- lock.release()
- # wait a bit to allow most threads to finish now
- while count[0] > 10:
- print count[0] # <- releases the GIL
- print "ok."
- except (thread.error, MemoryError):
- pass
- else:
- raise Exception("could unexpectedly start 1000 threads")
- # safety: check that we can start a new thread here
- thread.start_new_thread(lambda: None, ())
-
def test_stack_size(self):
import thread
thread.stack_size(0)
@@ -256,3 +197,74 @@
waiting = []
thread.start_new_thread(f, ())
raises(KeyboardInterrupt, busy_wait)
+
+ at pytest.mark.skip("too slow")
+class _AppTestThread(GenericTestThread):
+ '''
+ This test is very slow, do not run it by default.
+ '''
+ def setup_class(cls):
+ GenericTestThread.setup_class.im_func(cls)
+ # if we cannot start more than, say, 1000 threads on this OS, then
+ # we can check that we get the proper error at app-level
+ space = cls.space
+ lock = thread.allocate_lock()
+ lock.acquire()
+ def f():
+ lock.acquire()
+ lock.release()
+ start = thread._count()
+ try:
+ try:
+ for i in range(1000):
+ thread.start_new_thread(f, ())
+ finally:
+ lock.release()
+ except (thread.error, MemoryError):
+ cls.w_can_start_many_threads = space.wrap(False)
+ else:
+ cls.w_can_start_many_threads = space.wrap(True)
+ # wait a bit to allow all threads to finish now
+ remaining = thread._count()
+ retries = 0
+ while remaining > start:
+ retries += 1
+ if retries == 200:
+ raise Exception("the test's threads don't stop!")
+ time.sleep(0.2)
+ remaining = thread._count()
+
+ def test_many_threads(self):
+ import time, sys
+ if sys.version_info[0] < 3:
+ import thread as _thread
+ else:
+ import _thread
+ if self.can_start_many_threads or sys.platform == 'win32':
+ skip("this OS supports too many threads to check (> 1000)")
+ lock = _thread.allocate_lock()
+ lock.acquire()
+ count = [0]
+ def f():
+ count[0] += 1
+ lock.acquire()
+ lock.release()
+ count[0] -= 1
+ try:
+ try:
+ for i in range(1000):
+ _thread.start_new_thread(f, ())
+ finally:
+ lock.release()
+ # wait a bit to allow most threads to finish now
+ while count[0] > 10:
+ print(count[0]) # <- releases the GIL
+ print("ok.")
+ except (_thread.error, MemoryError):
+ pass
+ else:
+ raise Exception("could unexpectedly start 1000 threads")
+ # safety: check that we can start a new thread here
+ _thread.start_new_thread(lambda: None, ())
+
+
More information about the pypy-commit
mailing list