Skip to content

Commit

Permalink
Tweak test timeout for PyPy.
Browse files Browse the repository at this point in the history
[skip appveyor]
  • Loading branch information
jamadden committed Jan 31, 2018
1 parent 029a8d9 commit 04e6015
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/greentest/greentest/__init__.py
Expand Up @@ -33,6 +33,7 @@
from greentest.sysinfo import CFFI_BACKEND
from greentest.sysinfo import DEBUG
from greentest.sysinfo import RUN_LEAKCHECKS
from greentest.sysinfo import RUN_COVERAGE

from greentest.sysinfo import PY2
from greentest.sysinfo import PY3
Expand Down
40 changes: 20 additions & 20 deletions src/greentest/test__threadpool.py
Expand Up @@ -74,12 +74,8 @@ def test_apply_raises(self):
def raiser():
raise ExpectedException()

try:
with self.assertRaises(ExpectedException):
pool.apply(raiser)
except ExpectedException:
pass
else:
self.fail("Should have raised ExpectedException")
# Don't let the metaclass automatically force any error
# that reaches the hub from a spawned greenlet to become
# fatal; that defeats the point of the test.
Expand All @@ -97,8 +93,8 @@ def test_init_valueerror(self):

class TimingWrapper(object):

def __init__(self, func):
self.func = func
def __init__(self, the_func):
self.func = the_func
self.elapsed = None

def __call__(self, *args, **kwds):
Expand Down Expand Up @@ -147,10 +143,10 @@ def test_map(self):
SMALL_RANGE = 10
LARGE_RANGE = 1000

if greentest.PYPY and greentest.WIN:
# PyPy 5.9 is *really* slow at spawning or switching between threads on Windows
# Tests that happen instantaneously on other platforms
# time out due to the overhead
if greentest.PYPY and (greentest.WIN or greentest.RUN_COVERAGE):
# PyPy 5.10 is *really* slow at spawning or switching between
# threads (especially on Windows or when coverage is enabled) Tests that happen
# instantaneously on other platforms time out due to the overhead
LARGE_RANGE = 50

class TestPool(_AbstractPoolTest):
Expand All @@ -168,7 +164,7 @@ def test_async(self):

def test_async_callback(self):
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)
self.assertEqual(get(), 49)
self.assertTimeoutAlmostEqual(get.elapsed, TIMEOUT1, 1)
Expand Down Expand Up @@ -208,10 +204,11 @@ def test_imap_gc(self):
def test_imap_unordered_gc(self):
it = self.pool.imap_unordered(sqr, range(SMALL_RANGE))
result = []
for i in range(SMALL_RANGE):
for _ in range(SMALL_RANGE):
result.append(six.advance_iterator(it))
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)])

def test_imap_random(self):
Expand Down Expand Up @@ -439,9 +436,10 @@ def test(self):
if PYPY:
gc.collect()
gc.collect()
for index, r in enumerate(refs):
assert r() is None, (index, r(), greentest.getrefcount(r()), refs)
assert len(refs) == 4, refs
for r in refs:
self.assertIsNone(r())

self.assertEqual(4, len(refs))


class Object(object):
Expand All @@ -450,21 +448,23 @@ class Object(object):

class SomeClass(object):

refs = None

def func(self, arg1, kwarg1=None):
result = Object()
self.refs.extend([weakref.ref(x) for x in [arg1, kwarg1, result]])
return result


def func():
def noop():
pass


class TestRefCount(TestCase):

def test(self):
pool = ThreadPool(1)
pool.spawn(func)
pool.spawn(noop)
gevent.sleep(0)
pool.kill()

Expand Down Expand Up @@ -499,7 +499,7 @@ def fn():

def callback(future):
future.calledback += 1
raise Exception("Expected, ignored")
raise greentest.ExpectedException("Expected, ignored")

future = pool.submit(fn)
future.calledback = 0
Expand Down

0 comments on commit 04e6015

Please sign in to comment.