Commit 1910b1d6 authored by Jason Madden's avatar Jason Madden

Use assertTimeWithinRange for better control on PyPy/Windows.

parent 23f32416
...@@ -34,6 +34,22 @@ from greentest import flaky ...@@ -34,6 +34,22 @@ from greentest import flaky
from greentest.patched_tests_setup import get_switch_expected from greentest.patched_tests_setup import get_switch_expected
class TimeAssertMixin(object):
def assertTimeoutAlmostEqual(self, first, second, places=None, msg=None, delta=None):
try:
self.assertAlmostEqual(first, second, places=places, msg=msg, delta=delta)
except AssertionError:
flaky.reraiseFlakyTestTimeout()
if sysinfo.EXPECT_POOR_TIMER_RESOLUTION:
# pylint:disable=unused-argument
def assertTimeWithinRange(self, delay, min_time, max_time):
return
else:
def assertTimeWithinRange(self, time_taken, min_time, max_time):
self.assertLessEqual(time_taken, max_time)
self.assertGreaterEqual(time_taken, min_time)
...@@ -101,7 +117,7 @@ class TestCaseMetaClass(type): ...@@ -101,7 +117,7 @@ class TestCaseMetaClass(type):
def _noop(): def _noop():
return return
class TestCase(TestCaseMetaClass("NewBase", (BaseTestCase,), {})): class TestCase(TestCaseMetaClass("NewBase", (TimeAssertMixin, BaseTestCase,), {})):
__timeout__ = params.LOCAL_TIMEOUT if not sysinfo.RUNNING_ON_CI else params.CI_TIMEOUT __timeout__ = params.LOCAL_TIMEOUT if not sysinfo.RUNNING_ON_CI else params.CI_TIMEOUT
switch_expected = 'default' switch_expected = 'default'
...@@ -225,23 +241,6 @@ class TestCase(TestCaseMetaClass("NewBase", (BaseTestCase,), {})): ...@@ -225,23 +241,6 @@ class TestCase(TestCaseMetaClass("NewBase", (BaseTestCase,), {})):
self.assertIsInstance(econtext, where_type) self.assertIsInstance(econtext, where_type)
return error return error
def assertTimeoutAlmostEqual(self, first, second, places=None, msg=None, delta=None):
try:
self.assertAlmostEqual(first, second, places=places, msg=msg, delta=delta)
except AssertionError:
flaky.reraiseFlakyTestTimeout()
if sysinfo.EXPECT_POOR_TIMER_RESOLUTION:
# pylint:disable=unused-argument
def assertTimeWithinRange(self, delay, min_time, max_time):
return
else:
def assertTimeWithinRange(self, time_taken, min_time, max_time):
self.assertLessEqual(time_taken, max_time)
self.assertGreaterEqual(time_taken, min_time)
def assertMonkeyPatchedFuncSignatures(self, mod_name, func_names=(), exclude=()): def assertMonkeyPatchedFuncSignatures(self, mod_name, func_names=(), exclude=()):
# We use inspect.getargspec because it's the only thing available # We use inspect.getargspec because it's the only thing available
# in Python 2.7, but it is deprecated # in Python 2.7, but it is deprecated
......
...@@ -74,7 +74,9 @@ if sys.platform == 'win32': ...@@ -74,7 +74,9 @@ if sys.platform == 'win32':
# This one sometimes seems to just stop right after # This one sometimes seems to just stop right after
# patching is done. It passes on a local win 10 vm, and the main # patching is done. It passes on a local win 10 vm, and the main
# test_threading_2.py does as well. # test_threading_2.py does as well.
# https://ci.appveyor.com/project/denik/gevent/build/1.0.1275/job/3uxm8y463v3p6d87#L1182 # Based on the printouts we added, it appears to not even
# finish importing:
# https://ci.appveyor.com/project/denik/gevent/build/1.0.1277/job/tpvhesij5gldjxqw#L1190
'FLAKY test_threading.py', 'FLAKY test_threading.py',
] ]
......
...@@ -15,6 +15,7 @@ try: ...@@ -15,6 +15,7 @@ try:
except ImportError: except ImportError:
from test import test_support as support from test import test_support as support
from greentest.testcase import TimeAssertMixin
def _wait(): def _wait():
# A crude wait/yield function not relying on synchronization primitives. # A crude wait/yield function not relying on synchronization primitives.
...@@ -59,7 +60,7 @@ class Bunch(object): ...@@ -59,7 +60,7 @@ class Bunch(object):
self._can_exit = True self._can_exit = True
class BaseTestCase(unittest.TestCase): class BaseTestCase(TimeAssertMixin, unittest.TestCase):
def setUp(self): def setUp(self):
self._threads = support.threading_setup() self._threads = support.threading_setup()
...@@ -306,7 +307,7 @@ class EventTests(BaseTestCase): ...@@ -306,7 +307,7 @@ class EventTests(BaseTestCase):
self.assertEqual(results1, [False] * N) self.assertEqual(results1, [False] * N)
for r, dt in results2: for r, dt in results2:
self.assertFalse(r) self.assertFalse(r)
self.assertTrue(dt >= 0.19, dt) # XXX: libuv sometimes produces 0.19958 self.assertTimeWithinRange(dt, 0.18, 10)
# The event is set # The event is set
results1 = [] results1 = []
results2 = [] results2 = []
......
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