Commit e075751c authored by Jason Madden's avatar Jason Madden

Merge branch 'issue1711'

parents 19cf5f4a 2d8a5636
......@@ -58,14 +58,14 @@ class TimeAssertMixin(object):
self.assertGreaterEqual(time_taken, min_time)
@contextmanager
def runs_in_given_time(self, expected, fuzzy=None):
def runs_in_given_time(self, expected, fuzzy=None, min_time=None):
if fuzzy is None:
if sysinfo.EXPECT_POOR_TIMER_RESOLUTION or sysinfo.LIBUV:
# The noted timer jitter issues on appveyor/pypy3
fuzzy = expected * 5.0
else:
fuzzy = expected / 2.0
min_time = expected - fuzzy
min_time = min_time if min_time is not None else expected - fuzzy
max_time = expected + fuzzy
start = perf_counter()
yield (min_time, max_time)
......@@ -73,8 +73,8 @@ class TimeAssertMixin(object):
try:
self.assertTrue(
min_time <= elapsed <= max_time,
'Expected: %r; elapsed: %r; fuzzy %r; clock_info: %s' % (
expected, elapsed, fuzzy, get_clock_info('perf_counter')
'Expected: %r; elapsed: %r; min: %r; max: %r; fuzzy %r; clock_info: %s' % (
expected, elapsed, min_time, max_time, fuzzy, get_clock_info('perf_counter')
))
except AssertionError:
flaky.reraiseFlakyTestRaceCondition()
......
......@@ -212,7 +212,7 @@ class TestPool(_AbstractPoolTest):
self.assertEqual(get(), 49)
self.assertTimeoutAlmostEqual(get.elapsed, TIMEOUT1, 1)
gevent.sleep(0) # lets the callback run
assert result == [49], result
self.assertEqual(result, [49])
def test_async_timeout(self):
res = self.pool.apply_async(sqr, (6, TIMEOUT2 + 0.2))
......@@ -273,10 +273,11 @@ class TestPool(_AbstractPoolTest):
size = self.size or 10
result = self.pool.map_async(sleep, [0.1] * (size * 2))
gevent.sleep(0.1)
kill = TimingWrapper(self.pool.kill)
kill()
assert kill.elapsed < 0.1 * self.size + 0.5, kill.elapsed
result.join()
try:
with self.runs_in_given_time(0.1 * self.size + 0.5, min_time=0):
self.pool.kill()
finally:
result.join()
def sleep(self, x):
sleep(float(x) / 10.0)
......@@ -485,7 +486,7 @@ class TestRef(TestCase):
# result = func(Object(), kwarg1=Object())
# but in a thread pool and see that arguments', result's and func's references are not leaked
result = pool.apply(func, (Object(), ), {'kwarg1': Object()})
assert isinstance(result, Object), repr(result)
self.assertIsInstance(result, Object)
gevent.sleep(0.1) # XXX should not be needed
refs.append(weakref.ref(func))
......
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