Commit 6390aec4 authored by Jason Madden's avatar Jason Madden

Debugging the test__core.py memory corruption bug seen on travis.

parent cbae4c9b
...@@ -11,16 +11,16 @@ env: ...@@ -11,16 +11,16 @@ env:
# These are ordered to get as much diversity in the # These are ordered to get as much diversity in the
# first group of parallel runs (4) as posible # first group of parallel runs (4) as posible
- TASK=test-py27-libuv - TASK=test-py27-libuv
- TASK=test-py27-noembed #- TASK=test-py27-noembed
- TASK=test-pypy #- TASK=test-pypy
- TASK=test-py36 #- TASK=test-py36
- TASK=lint-py27 - TASK=lint-py27
- TASK=test-pypy3 #- TASK=test-pypy3
- TASK=test-py35 #- TASK=test-py35
- TASK=test-py278 #- TASK=test-py278
- TASK=test-py27 #- TASK=test-py27
- TASK=test-py34 #- TASK=test-py34
- TASK=test-py27-cffi #- TASK=test-py27-cffi
matrix: matrix:
fast_finish: true fast_finish: true
......
""" """
libuv loop implementation libuv loop implementation
""" """
# pylint: disable=no-member
from __future__ import absolute_import, print_function from __future__ import absolute_import, print_function
import os import os
...@@ -15,8 +15,8 @@ from gevent._ffi.loop import AbstractLoop ...@@ -15,8 +15,8 @@ from gevent._ffi.loop import AbstractLoop
from gevent.libuv import _corecffi # pylint:disable=no-name-in-module,import-error from gevent.libuv import _corecffi # pylint:disable=no-name-in-module,import-error
from gevent._ffi.loop import assign_standard_callbacks from gevent._ffi.loop import assign_standard_callbacks
ffi = _corecffi.ffi # pylint:disable=no-member ffi = _corecffi.ffi
libuv = _corecffi.lib # pylint:disable=no-member libuv = _corecffi.lib
__all__ = [ __all__ = [
] ]
......
# pylint: disable=too-many-lines, protected-access, redefined-outer-name, not-callable # pylint: disable=too-many-lines, protected-access, redefined-outer-name, not-callable
# pylint: disable=no-member
from __future__ import absolute_import, print_function from __future__ import absolute_import, print_function
import functools import functools
...@@ -6,8 +7,8 @@ import weakref ...@@ -6,8 +7,8 @@ import weakref
import gevent.libuv._corecffi as _corecffi # pylint:disable=no-name-in-module,import-error import gevent.libuv._corecffi as _corecffi # pylint:disable=no-name-in-module,import-error
ffi = _corecffi.ffi # pylint:disable=no-member ffi = _corecffi.ffi
libuv = _corecffi.lib # pylint:disable=no-member libuv = _corecffi.lib
from gevent._ffi import watcher as _base from gevent._ffi import watcher as _base
......
...@@ -42,6 +42,7 @@ import _six as six ...@@ -42,6 +42,7 @@ import _six as six
PYPY = hasattr(sys, 'pypy_version_info') PYPY = hasattr(sys, 'pypy_version_info')
VERBOSE = sys.argv.count('-v') > 1 VERBOSE = sys.argv.count('-v') > 1
LIBUV = os.getenv('GEVENT_CORE_CFFI_ONLY') == 'libuv' # XXX: Formalize this better
if '--debug-greentest' in sys.argv: if '--debug-greentest' in sys.argv:
sys.argv.remove('--debug-greentest') sys.argv.remove('--debug-greentest')
...@@ -138,6 +139,11 @@ skipIf = unittest.skipIf ...@@ -138,6 +139,11 @@ skipIf = unittest.skipIf
EXPECT_POOR_TIMER_RESOLUTION = PYPY3 or RUNNING_ON_APPVEYOR EXPECT_POOR_TIMER_RESOLUTION = PYPY3 or RUNNING_ON_APPVEYOR
if LIBUV:
skipOnLibuv = unittest.skip
else:
skipOnLibuv = _do_not_skip
class ExpectedException(Exception): class ExpectedException(Exception):
"""An exception whose traceback should be ignored""" """An exception whose traceback should be ignored"""
......
# pylint:disable=no-member
import sys import sys
from greentest import TestCase, main
from gevent import core
import unittest import unittest
from greentest import main, skipOnLibuv
from gevent import core
@unittest.skip("Debugging")
class Test(TestCase): class TestCore(unittest.TestCase):
switch_expected = False
__timeout__ = None
def test_get_version(self): def test_get_version(self):
version = core.get_version() version = core.get_version()
assert isinstance(version, str), repr(version) self.assertIsInstance(version, str)
assert version, repr(version) self.assertTrue(version)
header_version = core.get_header_version() header_version = core.get_header_version()
assert isinstance(header_version, str), repr(header_version) self.assertIsInstance(header_version, str)
assert header_version, repr(header_version) self.assertTrue(header_version)
self.assertEqual(version, header_version) self.assertEqual(version, header_version)
@unittest.skipIf(hasattr(core, 'libuv'), class TestWatchers(unittest.TestCase):
"flags are libev-only")
def test_flags_conversion(self):
if sys.platform != 'win32':
self.assertEqual(core.loop(2, default=False).backend_int, 2)
self.assertEqual(core.loop('select', default=False).backend, 'select')
self.assertEqual(core._flags_to_int(None), 0)
self.assertEqual(core._flags_to_int(['kqueue', 'SELECT']), core.BACKEND_KQUEUE | core.BACKEND_SELECT)
self.assertEqual(core._flags_to_list(core.BACKEND_PORT | core.BACKEND_POLL), ['port', 'poll'])
self.assertRaises(ValueError, core.loop, ['port', 'blabla'])
self.assertRaises(TypeError, core.loop, object())
def test_events_conversion(self):
self.assertEqual(core._events_to_str(core.READ | core.WRITE), 'READ|WRITE')
def test_EVENTS(self):
self.assertEqual(str(core.EVENTS), 'gevent.core.EVENTS')
self.assertEqual(repr(core.EVENTS), 'gevent.core.EVENTS')
def test_io(self): def test_io(self):
if sys.platform == 'win32': if sys.platform == 'win32':
...@@ -43,10 +25,13 @@ class Test(TestCase): ...@@ -43,10 +25,13 @@ class Test(TestCase):
else: else:
Error = ValueError Error = ValueError
win32 = False win32 = False
self.assertRaises(Error, core.loop().io, -1, 1) with self.assertRaises(Error):
core.loop().io(-1, 1)
if hasattr(core, 'TIMER'): if hasattr(core, 'TIMER'):
# libev # libev
self.assertRaises(ValueError, core.loop().io, 1, core.TIMER) with self.assertRaises(ValueError):
core.loop().io(1, core.TIMER)
# Test we can set events and io before it's started # Test we can set events and io before it's started
if not win32: if not win32:
# We can't do this with arbitrary FDs on windows; # We can't do this with arbitrary FDs on windows;
...@@ -61,12 +46,36 @@ class Test(TestCase): ...@@ -61,12 +46,36 @@ class Test(TestCase):
else: else:
self.assertEqual(core._events_to_str(io.events), 'WRITE') self.assertEqual(core._events_to_str(io.events), 'WRITE')
def test_timer(self): def test_timer_constructor(self):
self.assertRaises(ValueError, core.loop().timer, 1, -1) with self.assertRaises(ValueError):
core.loop().timer(1, -1)
def test_signal(self): def test_signal_constructor(self):
self.assertRaises(ValueError, core.loop().signal, 1000) with self.assertRaises(ValueError):
core.loop().signal(1000)
@skipOnLibuv("Tests for libev-only functions")
class TestLibev(unittest.TestCase):
def test_flags_conversion(self):
if sys.platform != 'win32':
self.assertEqual(core.loop(2, default=False).backend_int, 2)
self.assertEqual(core.loop('select', default=False).backend, 'select')
self.assertEqual(core._flags_to_int(None), 0)
self.assertEqual(core._flags_to_int(['kqueue', 'SELECT']), core.BACKEND_KQUEUE | core.BACKEND_SELECT)
self.assertEqual(core._flags_to_list(core.BACKEND_PORT | core.BACKEND_POLL), ['port', 'poll'])
self.assertRaises(ValueError, core.loop, ['port', 'blabla'])
self.assertRaises(TypeError, core.loop, object())
class TestEvents(unittest.TestCase):
def test_events_conversion(self):
self.assertEqual(core._events_to_str(core.READ | core.WRITE), 'READ|WRITE')
def test_EVENTS(self):
self.assertEqual(str(core.EVENTS), 'gevent.core.EVENTS')
self.assertEqual(repr(core.EVENTS), 'gevent.core.EVENTS')
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