Commit 3deb1c4e authored by Jason Madden's avatar Jason Madden

Clean up a ResourceWarning and actually test what we're trying to test on CPython 3.

parent d069c6ef
...@@ -237,6 +237,7 @@ if PYPY: ...@@ -237,6 +237,7 @@ if PYPY:
FAILING_TESTS += [ FAILING_TESTS += [
# A few errors and differences: # A few errors and differences:
# AssertionError: ('255.255.255.255', 'http') != gaierror(-2,) # DNS Python
# AssertionError: ('255.255.255.255', 'http') != gaierror(4, 'ARES_ENOTFOUND: Domain name not found') # AssertionError: ('255.255.255.255', 'http') != gaierror(4, 'ARES_ENOTFOUND: Domain name not found')
# AssertionError: OverflowError('port must be 0-65535.',) != ('readthedocs.org', '65535') # AssertionError: OverflowError('port must be 0-65535.',) != ('readthedocs.org', '65535')
# AssertionError: Lists differ: # AssertionError: Lists differ:
......
...@@ -24,6 +24,10 @@ def _find_files_to_ignore(): ...@@ -24,6 +24,10 @@ def _find_files_to_ignore():
'psycopg2_pool.py', 'psycopg2_pool.py',
'geventsendfile.py', 'geventsendfile.py',
] ]
if greentest.PYPY and greentest.RUNNING_ON_APPVEYOR:
# For some reason on Windows with PyPy, this times out,
# when it should be very fast.
result.append("processes.py")
result += [x[14:] for x in glob.glob('test__example_*.py')] result += [x[14:] for x in glob.glob('test__example_*.py')]
finally: finally:
...@@ -34,7 +38,7 @@ def _find_files_to_ignore(): ...@@ -34,7 +38,7 @@ def _find_files_to_ignore():
default_time_range = (2, 4) default_time_range = (2, 4)
time_ranges = { time_ranges = {
'concurrent_download.py': (0, 30), 'concurrent_download.py': (0, 30),
'processes.py': (0, 10) 'processes.py': (0, 4)
} }
class _AbstractTestMixin(util.ExampleMixin): class _AbstractTestMixin(util.ExampleMixin):
......
...@@ -22,12 +22,11 @@ import gevent ...@@ -22,12 +22,11 @@ import gevent
from gevent import socket from gevent import socket
from gevent.testing import TestCase, main, tcp_listener from gevent.testing import TestCase, main, tcp_listener
from gevent.testing import gc_collect_if_needed
from gevent.testing import skipOnPyPy from gevent.testing import skipOnPyPy
from gevent.testing import params from gevent.testing import params
PYPY = hasattr(sys, 'pypy_version_info')
PY3 = sys.version_info[0] >= 3 PY3 = sys.version_info[0] >= 3
...@@ -91,28 +90,40 @@ class TestGreenIo(TestCase): ...@@ -91,28 +90,40 @@ class TestGreenIo(TestCase):
did_it_work(server) did_it_work(server)
server_greenlet.kill() server_greenlet.kill()
@skipOnPyPy("GC is different") @skipOnPyPy("Takes multiple GCs and issues a warning we can't catch")
def test_del_closes_socket(self): def test_del_closes_socket(self):
import warnings
def accept_once(listener): def accept_once(listener):
# delete/overwrite the original conn # delete/overwrite the original conn
# object, only keeping the file object around # object, only keeping the file object around
# closing the file object should close everything # closing the file object should close everything
# XXX: This is not exactly true on Python 3. # This is not *exactly* true on Python 3. This produces
# This produces a ResourceWarning. # a ResourceWarning, which we silence below. (Previously we actually
oconn = None # *saved* a reference to the socket object, so we
# weren't testing what we thought we were.)
# It's definitely not true on PyPy, which needs GC to
# reliably close everything; sometimes this is more than
# one collection cycle. And PyPy issues a warning with -X
# track-resources that we cannot catch.
with warnings.catch_warnings():
warnings.simplefilter('ignore')
try: try:
conn, _ = listener.accept() conn = listener.accept()[0]
if PY3: # Note that we overwrite the original variable,
oconn = conn # losing our reference to the socket.
conn = conn.makefile(mode='wb') conn = conn.makefile(mode='wb')
conn.write(b'hello\n') conn.write(b'hello\n')
conn.close() conn.close()
_write_to_closed(conn, b'a') _write_to_closed(conn, b'a')
finally: finally:
listener.close() listener.close()
if oconn is not None: del listener
oconn.close() del conn
gc_collect_if_needed()
gc_collect_if_needed()
server = tcp_listener() server = tcp_listener()
gevent.spawn(accept_once, server) gevent.spawn(accept_once, server)
...@@ -121,8 +132,14 @@ class TestGreenIo(TestCase): ...@@ -121,8 +132,14 @@ class TestGreenIo(TestCase):
fd = client.makefile() fd = client.makefile()
client.close() client.close()
self.assertEqual(fd.read(), 'hello\n') self.assertEqual(fd.read(), 'hello\n')
# If the socket isn't closed when 'accept_once' finished,
# then this will hang and exceed the timeout
self.assertEqual(fd.read(), '') self.assertEqual(fd.read(), '')
fd.close()
del client
del fd
if __name__ == '__main__': if __name__ == '__main__':
main() main()
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