Commit 04e60158 authored by Jason Madden's avatar Jason Madden

Tweak test timeout for PyPy.

[skip appveyor]
parent 029a8d9f
...@@ -33,6 +33,7 @@ from greentest.sysinfo import LIBUV ...@@ -33,6 +33,7 @@ from greentest.sysinfo import LIBUV
from greentest.sysinfo import CFFI_BACKEND from greentest.sysinfo import CFFI_BACKEND
from greentest.sysinfo import DEBUG from greentest.sysinfo import DEBUG
from greentest.sysinfo import RUN_LEAKCHECKS from greentest.sysinfo import RUN_LEAKCHECKS
from greentest.sysinfo import RUN_COVERAGE
from greentest.sysinfo import PY2 from greentest.sysinfo import PY2
from greentest.sysinfo import PY3 from greentest.sysinfo import PY3
......
...@@ -74,12 +74,8 @@ class PoolBasicTests(TestCase): ...@@ -74,12 +74,8 @@ class PoolBasicTests(TestCase):
def raiser(): def raiser():
raise ExpectedException() raise ExpectedException()
try: with self.assertRaises(ExpectedException):
pool.apply(raiser) pool.apply(raiser)
except ExpectedException:
pass
else:
self.fail("Should have raised ExpectedException")
# Don't let the metaclass automatically force any error # Don't let the metaclass automatically force any error
# that reaches the hub from a spawned greenlet to become # that reaches the hub from a spawned greenlet to become
# fatal; that defeats the point of the test. # fatal; that defeats the point of the test.
...@@ -97,8 +93,8 @@ class PoolBasicTests(TestCase): ...@@ -97,8 +93,8 @@ class PoolBasicTests(TestCase):
class TimingWrapper(object): class TimingWrapper(object):
def __init__(self, func): def __init__(self, the_func):
self.func = func self.func = the_func
self.elapsed = None self.elapsed = None
def __call__(self, *args, **kwds): def __call__(self, *args, **kwds):
...@@ -147,10 +143,10 @@ class _AbstractPoolTest(TestCase): ...@@ -147,10 +143,10 @@ class _AbstractPoolTest(TestCase):
SMALL_RANGE = 10 SMALL_RANGE = 10
LARGE_RANGE = 1000 LARGE_RANGE = 1000
if greentest.PYPY and greentest.WIN: if greentest.PYPY and (greentest.WIN or greentest.RUN_COVERAGE):
# PyPy 5.9 is *really* slow at spawning or switching between threads on Windows # PyPy 5.10 is *really* slow at spawning or switching between
# Tests that happen instantaneously on other platforms # threads (especially on Windows or when coverage is enabled) Tests that happen
# time out due to the overhead # instantaneously on other platforms time out due to the overhead
LARGE_RANGE = 50 LARGE_RANGE = 50
class TestPool(_AbstractPoolTest): class TestPool(_AbstractPoolTest):
...@@ -168,7 +164,7 @@ class TestPool(_AbstractPoolTest): ...@@ -168,7 +164,7 @@ class TestPool(_AbstractPoolTest):
def test_async_callback(self): def test_async_callback(self):
result = [] result = []
res = self.pool.apply_async(sqr, (7, TIMEOUT1,), callback=lambda x: result.append(x)) res = self.pool.apply_async(sqr, (7, TIMEOUT1,), callback=result.append)
get = TimingWrapper(res.get) get = TimingWrapper(res.get)
self.assertEqual(get(), 49) self.assertEqual(get(), 49)
self.assertTimeoutAlmostEqual(get.elapsed, TIMEOUT1, 1) self.assertTimeoutAlmostEqual(get.elapsed, TIMEOUT1, 1)
...@@ -208,10 +204,11 @@ class TestPool(_AbstractPoolTest): ...@@ -208,10 +204,11 @@ class TestPool(_AbstractPoolTest):
def test_imap_unordered_gc(self): def test_imap_unordered_gc(self):
it = self.pool.imap_unordered(sqr, range(SMALL_RANGE)) it = self.pool.imap_unordered(sqr, range(SMALL_RANGE))
result = [] result = []
for i in range(SMALL_RANGE): for _ in range(SMALL_RANGE):
result.append(six.advance_iterator(it)) result.append(six.advance_iterator(it))
gc.collect() gc.collect()
self.assertRaises(StopIteration, lambda: six.advance_iterator(it)) with self.assertRaises(StopIteration):
six.advance_iterator(it)
self.assertEqual(sorted(result), [x * x for x in range(SMALL_RANGE)]) self.assertEqual(sorted(result), [x * x for x in range(SMALL_RANGE)])
def test_imap_random(self): def test_imap_random(self):
...@@ -439,9 +436,10 @@ class TestRef(TestCase): ...@@ -439,9 +436,10 @@ class TestRef(TestCase):
if PYPY: if PYPY:
gc.collect() gc.collect()
gc.collect() gc.collect()
for index, r in enumerate(refs): for r in refs:
assert r() is None, (index, r(), greentest.getrefcount(r()), refs) self.assertIsNone(r())
assert len(refs) == 4, refs
self.assertEqual(4, len(refs))
class Object(object): class Object(object):
...@@ -450,13 +448,15 @@ class Object(object): ...@@ -450,13 +448,15 @@ class Object(object):
class SomeClass(object): class SomeClass(object):
refs = None
def func(self, arg1, kwarg1=None): def func(self, arg1, kwarg1=None):
result = Object() result = Object()
self.refs.extend([weakref.ref(x) for x in [arg1, kwarg1, result]]) self.refs.extend([weakref.ref(x) for x in [arg1, kwarg1, result]])
return result return result
def func(): def noop():
pass pass
...@@ -464,7 +464,7 @@ class TestRefCount(TestCase): ...@@ -464,7 +464,7 @@ class TestRefCount(TestCase):
def test(self): def test(self):
pool = ThreadPool(1) pool = ThreadPool(1)
pool.spawn(func) pool.spawn(noop)
gevent.sleep(0) gevent.sleep(0)
pool.kill() pool.kill()
...@@ -499,7 +499,7 @@ if hasattr(gevent.threadpool, 'ThreadPoolExecutor'): ...@@ -499,7 +499,7 @@ if hasattr(gevent.threadpool, 'ThreadPoolExecutor'):
def callback(future): def callback(future):
future.calledback += 1 future.calledback += 1
raise Exception("Expected, ignored") raise greentest.ExpectedException("Expected, ignored")
future = pool.submit(fn) future = pool.submit(fn)
future.calledback = 0 future.calledback = 0
......
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