Commit 2545c60c authored by Jason Madden's avatar Jason Madden

Working on some flaky appveyor tests.

parent 5a8d1254
......@@ -96,7 +96,7 @@ if sysinfo.RUNNING_ON_CI or (sysinfo.PYPY and sysinfo.WIN):
reraiseFlakyTestTimeoutLibuv = reraiseFlakyTestTimeout
def reraises_flaky_timeout(exc_kind):
def reraises_flaky_timeout(exc_kind=AssertionError, _func=reraiseFlakyTestTimeout):
def wrapper(f):
@functools.wraps(f)
......@@ -104,7 +104,10 @@ def reraises_flaky_timeout(exc_kind):
try:
f(*args)
except exc_kind:
reraiseFlakyTestTimeout()
_func()
return m
return wrapper
def reraises_flaky_race_condition(exc_kind=AssertionError):
return reraises_flaky_timeout(exc_kind, _func=reraiseFlakyTestRaceCondition)
......@@ -34,6 +34,8 @@ from .sysinfo import OSX
from .sysinfo import LIBUV
from .sysinfo import CFFI_BACKEND
from . import flaky
CPYTHON = not PYPY
# By default, test cases are expected to switch and emit warnings if there was none
......@@ -536,6 +538,14 @@ def _gc_at_end():
gc.collect()
gc.collect()
@contextlib.contextmanager
def _flaky_socket_timeout():
import socket
try:
yield
except socket.timeout:
flaky.reraiseFlakyTestTimeout()
# Map from FQN to a context manager that will be wrapped around
# that test.
wrapped_tests = {
......@@ -577,6 +587,10 @@ if WIN:
'test_ssl.ThreadedTests.test_socketserver',
]
wrapped_tests.update({
'test_socket.SendfileUsingSendTest.testWithTimeout': _flaky_socket_timeout
})
if PYPY:
disabled_tests += [
# Does not exist in the CPython test suite, tests for a specific bug
......@@ -1085,9 +1099,10 @@ def disable_tests_in_source(source, filename):
# so use [ \t]+. Without indentation, test_main, commonly used as the
# __main__ function at the top level, could get matched. \s matches
# newlines even in MULTILINE mode so it would still match that.
my_disabled_testcases = set()
for test in my_disabled_tests:
testcase = test.split('.')[-1]
my_disabled_testcases.add(testcase)
# def foo_bar(self)
# ->
# @_GEVENT_UTS.skip('Removed by patched_tests_setup')
......@@ -1101,6 +1116,10 @@ def disable_tests_in_source(source, filename):
for test in my_wrapped_tests:
testcase = test.split('.')[-1]
if testcase in my_disabled_testcases:
print("Not wrapping %s because it is skipped" % (test,))
continue
# def foo_bar(self)
# ->
# @_GEVENT_PTS._PatchedTest('file.Case.name')
......
......@@ -37,6 +37,7 @@ from . import flaky
from .patched_tests_setup import get_switch_expected
class TimeAssertMixin(object):
@flaky.reraises_flaky_timeout()
def assertTimeoutAlmostEqual(self, first, second, places=None, msg=None, delta=None):
try:
self.assertAlmostEqual(first, second, places=places, msg=msg, delta=delta)
......@@ -64,9 +65,12 @@ class TimeAssertMixin(object):
start = time()
yield
elapsed = time() - start
try:
self.assertTrue(
expected - fuzzy <= elapsed <= expected + fuzzy,
'Expected: %r; elapsed: %r; fuzzy %r' % (expected, elapsed, fuzzy))
except AssertionError:
flaky.reraiseFlakyTestRaceCondition()
def runs_in_no_time(
self,
......
......@@ -85,6 +85,32 @@ if sys.platform == 'win32':
# too tight for appveyor. This happens even if Event isn't
# monkey-patched
'FLAKY test_threading.py',
# Starting in November 2018, on Python 3.7.0, we observe this test crashing.
# I can't reproduce locally.
# | C:\Python37-x64\python.exe -u -mgevent.tests.test__greenness
# 127.0.0.1 - - [09/Nov/2018 16:34:12] code 501, message Unsupported method ('GET')
# 127.0.0.1 - - [09/Nov/2018 16:34:12] "GET / HTTP/1.1" 501 -
# .
# ----------------------------------------------------------------------
# Ran 1 test in 0.031s
# OK
# Windows fatal exception: access violation
# Current thread 0x000003c8 (most recent call first):
# File "c:\projects\gevent\src\gevent\threadpool.py", line 261 in _worker
# Thread 0x00000600 (most recent call first):
# File "c:\projects\gevent\src\gevent\libuv\watcher.py", line 577 in send
# File "c:\projects\gevent\src\gevent\threadpool.py", line 408 in set
# File "c:\projects\gevent\src\gevent\threadpool.py", line 290 in _worker
# Thread 0x000007d4 (most recent call first):
# File "C:\Python37-x64\lib\weakref.py", line 356 in remove
# ! C:\Python37-x64\python.exe -u -mgevent.tests.test__greenness [code 3221225477] [took 1.3s]
'FLAKY test__greenness.py',
]
if not PY35:
......
......@@ -31,6 +31,7 @@ from gevent import get_hub
from gevent.testing.timing import SMALL_TICK as DELAY
from gevent.testing import flaky
class Error(Exception):
......@@ -174,7 +175,7 @@ class Test(greentest.TestCase):
gc.collect()
self.assertFalse(err_ref(), err_ref)
@flaky.reraises_flaky_race_condition()
def test_nested_timeout(self):
with Timeout(DELAY, False):
with Timeout(DELAY * 10, False):
......
......@@ -385,7 +385,7 @@ class TestFDs(unittest.TestCase):
class RunFuncTestCase(greentest.TestCase):
# Based on code from python 3.6
__timeout__ = 6
__timeout__ = greentest.LARGE_TIMEOUT
def run_python(self, code, **kwargs):
"""Run Python code in a subprocess using subprocess.run"""
......
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