Commit 9535660a authored by Jason Madden's avatar Jason Madden

Rework the testrunner to group tests.

This almost cuts the test time in half on my machine.
parent 3f41248c
...@@ -25,6 +25,8 @@ from gevent.hub import Hub ...@@ -25,6 +25,8 @@ from gevent.hub import Hub
from .exception import ExpectedException from .exception import ExpectedException
class QuietHub(Hub): class QuietHub(Hub):
_resolver = None
_threadpool = None
EXPECTED_TEST_ERROR = (ExpectedException,) EXPECTED_TEST_ERROR = (ExpectedException,)
...@@ -42,3 +44,6 @@ class QuietHub(Hub): ...@@ -42,3 +44,6 @@ class QuietHub(Hub):
# see handle_error # see handle_error
return return
return Hub.print_exception(self, context, t, v, tb) return Hub.print_exception(self, context, t, v, tb)
def destroy(self, destroy_loop=None):
raise AssertionError("Do not destroy the hub in a unittest")
...@@ -1247,7 +1247,7 @@ disabled_tests += [ ...@@ -1247,7 +1247,7 @@ disabled_tests += [
'test_ssl.BasicSocketTests.test_openssl_version' 'test_ssl.BasicSocketTests.test_openssl_version'
] ]
if TRAVIS and OSX: if OSX:
disabled_tests += [ disabled_tests += [
# This sometimes produces OSError: Errno 40: Message too long # This sometimes produces OSError: Errno 40: Message too long
......
This diff is collapsed.
...@@ -29,7 +29,8 @@ class TestTimeout(greentest.TestCase): ...@@ -29,7 +29,8 @@ class TestTimeout(greentest.TestCase):
while True: while True:
listener.recvfrom(10000) listener.recvfrom(10000)
gevent.spawn(reader) greader = gevent.spawn(reader)
self._close_on_teardown(greader.kill)
r = Resolver(servers=[address[0]], timeout=0.001, tries=1, r = Resolver(servers=[address[0]], timeout=0.001, tries=1,
udp_port=address[-1]) udp_port=address[-1])
......
...@@ -158,4 +158,4 @@ class Test(greentest.TestCase): ...@@ -158,4 +158,4 @@ class Test(greentest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
greentest.main() greentest.main() # pragma: testrunner-no-combine
...@@ -7,18 +7,25 @@ try: ...@@ -7,18 +7,25 @@ try:
except ImportError: except ImportError:
import _thread as thread import _thread as thread
from gevent import testing as greentest
hub = gevent.get_hub() class Test(greentest.TestCase):
watcher = hub.loop.async_() def test(self):
hub = gevent.get_hub()
watcher = hub.loop.async_()
# BWC for <3.7: This should still be an attribute # BWC for <3.7: This should still be an attribute
assert hasattr(hub.loop, 'async') assert hasattr(hub.loop, 'async')
gevent.spawn_later(0.1, thread.start_new_thread, watcher.send, ()) gevent.spawn_later(0.1, thread.start_new_thread, watcher.send, ())
start = time.time() start = time.time()
with gevent.Timeout(1.0): # Large timeout for appveyor with gevent.Timeout(1.0): # Large timeout for appveyor
hub.wait(watcher) hub.wait(watcher)
print('Watcher %r reacted after %.6f seconds' % (watcher, time.time() - start - 0.1)) print('Watcher %r reacted after %.6f seconds' % (watcher, time.time() - start - 0.1))
if __name__ == '__main__':
greentest.main()
import gevent import gevent
from gevent.hub import get_hub from gevent.hub import get_hub
called = [] from gevent import testing as greentest
class Test(greentest.TestCase):
def f(): def test(self):
called.append(1) loop = get_hub().loop
called = []
def f():
called.append(1)
def main(): x = loop.run_callback(f)
loop = get_hub().loop
x = loop.run_callback(f)
assert x, x assert x, x
gevent.sleep(0) gevent.sleep(0)
assert called == [1], called assert called == [1], called
assert not x, (x, bool(x)) assert not x, (x, bool(x))
x = loop.run_callback(f) x = loop.run_callback(f)
assert x, x assert x, x
x.stop() x.stop()
assert not x, x assert not x, x
gevent.sleep(0) gevent.sleep(0)
assert called == [1], called assert called == [1], called
assert not x, x assert not x, x
if __name__ == '__main__': if __name__ == '__main__':
called[:] = [] greentest.main()
main()
...@@ -48,4 +48,4 @@ class TestDestroyHub(unittest.TestCase): ...@@ -48,4 +48,4 @@ class TestDestroyHub(unittest.TestCase):
hub.destroy() hub.destroy()
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main() # pragma: testrunner-no-combine
from __future__ import print_function, absolute_import from __future__ import print_function, absolute_import
from gevent import monkey; monkey.patch_all(subprocess=True) from gevent import monkey; monkey.patch_all()
import signal import signal
import socket import socket
......
from gevent import monkey from gevent import monkey
monkey.patch_all(subprocess=True) monkey.patch_all()
from gevent.server import DatagramServer from gevent.server import DatagramServer
......
...@@ -21,7 +21,8 @@ import sys ...@@ -21,7 +21,8 @@ import sys
import gevent import gevent
from gevent import socket from gevent import socket
from gevent.testing import TestCase, main, tcp_listener from gevent import testing as greentest
from gevent.testing import TestCase, tcp_listener
from gevent.testing import gc_collect_if_needed 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
...@@ -142,4 +143,4 @@ class TestGreenIo(TestCase): ...@@ -142,4 +143,4 @@ class TestGreenIo(TestCase):
if __name__ == '__main__': if __name__ == '__main__':
main() greentest.main()
import gevent import gevent
from gevent import testing as greentest
def func():
pass
class Test(greentest.TestCase):
a = gevent.spawn(func) def test(self):
b = gevent.spawn(func)
gevent.joinall([a, b, a]) def func():
pass
a = gevent.spawn(func)
b = gevent.spawn(func)
gevent.joinall([a, b, a])
if __name__ == '__main__':
greentest.main()
from gevent.core import loop from gevent import get_hub
from gevent import testing as greentest
count = 0 class Test(greentest.TestCase):
def test(self):
count = [0]
def incr():
count[0] += 1
def incr(): loop = get_hub().loop
global count loop.run_callback(incr)
count += 1 loop.run()
self.assertEqual(count, [1])
loop = loop()
loop.run_callback(incr) if __name__ == '__main__':
loop.run() greentest.main()
assert count == 1, count
import sys import sys
import unittest import unittest
from gevent.testing import TestCase, main from gevent.testing import TestCase
import gevent import gevent
from gevent.timeout import Timeout from gevent.timeout import Timeout
...@@ -53,4 +53,4 @@ class TestQueue(TestCase): # pragma: no cover ...@@ -53,4 +53,4 @@ class TestQueue(TestCase): # pragma: no cover
if __name__ == '__main__': if __name__ == '__main__':
main() unittest.main()
from subprocess import Popen
from gevent import monkey from gevent import monkey
monkey.patch_all() monkey.patch_all()
...@@ -79,6 +77,7 @@ class TestMonkey(SubscriberCleanupMixin, unittest.TestCase): ...@@ -79,6 +77,7 @@ class TestMonkey(SubscriberCleanupMixin, unittest.TestCase):
self.assertTrue(monkey.is_object_patched(modname, objname)) self.assertTrue(monkey.is_object_patched(modname, objname))
def test_patch_subprocess_twice(self): def test_patch_subprocess_twice(self):
Popen = monkey.get_original('subprocess', 'Popen')
self.assertNotIn('gevent', repr(Popen)) self.assertNotIn('gevent', repr(Popen))
self.assertIs(Popen, monkey.get_original('subprocess', 'Popen')) self.assertIs(Popen, monkey.get_original('subprocess', 'Popen'))
monkey.patch_subprocess() monkey.patch_subprocess()
......
...@@ -22,7 +22,7 @@ from __future__ import print_function ...@@ -22,7 +22,7 @@ from __future__ import print_function
from gevent import monkey from gevent import monkey
monkey.patch_all(thread=False) monkey.patch_all()
from contextlib import contextmanager from contextlib import contextmanager
try: try:
......
import unittest import unittest
import gevent.testing as greentest import gevent.testing as greentest
from gevent.testing import TestCase, main from gevent.testing import TestCase
import gevent import gevent
from gevent.hub import get_hub, LoopExit from gevent.hub import get_hub, LoopExit
from gevent import util from gevent import util
...@@ -462,4 +462,4 @@ del AbstractGenericGetTestCase ...@@ -462,4 +462,4 @@ del AbstractGenericGetTestCase
if __name__ == '__main__': if __name__ == '__main__':
main() greentest.main()
...@@ -6,24 +6,29 @@ Fails with PyPy 2.2.1 ...@@ -6,24 +6,29 @@ Fails with PyPy 2.2.1
""" """
from __future__ import print_function from __future__ import print_function
import sys import sys
import greenlet
from gevent import testing as greentest
print('Your greenlet version: %s' % (getattr(greenlet, '__version__', None), )) class Test(greentest.TestCase):
def test(self):
import greenlet
result = [] print('Your greenlet version: %s' % (getattr(greenlet, '__version__', None), ))
result = []
def func(): def func():
result.append(repr(sys.exc_info())) result.append(repr(sys.exc_info()))
g = greenlet.greenlet(func)
try:
1 / 0
except ZeroDivisionError:
g.switch()
g = greenlet.greenlet(func)
try:
1 / 0
except ZeroDivisionError:
g.switch()
self.assertEqual(result, ['(None, None, None)'])
assert result == ['(None, None, None)'], result if __name__ == '__main__':
greentest.main()
...@@ -140,7 +140,10 @@ class TestCase(greentest.TestCase): ...@@ -140,7 +140,10 @@ class TestCase(greentest.TestCase):
conn.close() conn.close()
ex = exc.exception ex = exc.exception
self.assertIn(ex.args[0], (errno.ECONNREFUSED, errno.EADDRNOTAVAIL), ex) self.assertIn(ex.args[0],
(errno.ECONNREFUSED, errno.EADDRNOTAVAIL,
errno.ECONNRESET, errno.ECONNABORTED),
(ex, ex.args))
def assert500(self): def assert500(self):
self.Settings.assert500(self) self.Settings.assert500(self)
......
...@@ -49,7 +49,7 @@ class Thread(_Thread): ...@@ -49,7 +49,7 @@ class Thread(_Thread):
class TestTCP(greentest.TestCase): class TestTCP(greentest.TestCase):
maxDiff = None
__timeout__ = None __timeout__ = None
TIMEOUT_ERROR = socket.timeout TIMEOUT_ERROR = socket.timeout
long_data = ", ".join([str(x) for x in range(20000)]) long_data = ", ".join([str(x) for x in range(20000)])
...@@ -210,7 +210,9 @@ class TestTCP(greentest.TestCase): ...@@ -210,7 +210,9 @@ class TestTCP(greentest.TestCase):
if match_data is None: if match_data is None:
match_data = self.long_data match_data = self.long_data
self.assertEqual(read_data, [match_data]) read_data = read_data[0].split(b',')
match_data = match_data.split(b',')
self.assertEqual(read_data, match_data)
def test_sendall_str(self): def test_sendall_str(self):
self._test_sendall(self.long_data) self._test_sendall(self.long_data)
......
""" """
Tests specifically for the monkey-patched threading module. Tests specifically for the monkey-patched threading module.
""" """
from gevent import monkey; monkey.patch_all() from gevent import monkey; monkey.patch_all() # pragma: testrunner-no-monkey-combine
import gevent.hub import gevent.hub
# check that the locks initialized by 'threading' did not init the hub # check that the locks initialized by 'threading' did not init the hub
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
import threading import threading
from gevent import monkey from gevent import monkey
monkey.patch_all() monkey.patch_all() # pragma: testrunner-no-monkey-combine
import gevent.testing as greentest import gevent.testing as greentest
......
...@@ -5,4 +5,4 @@ import threading ...@@ -5,4 +5,4 @@ import threading
# in python code, this used to throw RuntimeErro("Cannot release un-acquired lock") # in python code, this used to throw RuntimeErro("Cannot release un-acquired lock")
# See https://github.com/gevent/gevent/issues/615 # See https://github.com/gevent/gevent/issues/615
with threading.RLock(): with threading.RLock():
monkey.patch_all() monkey.patch_all() # pragma: testrunner-no-monkey-combine
...@@ -25,7 +25,7 @@ class Test(greentest.TestCase): ...@@ -25,7 +25,7 @@ class Test(greentest.TestCase):
def target(): def target():
tcurrent = threading.current_thread() tcurrent = threading.current_thread()
monkey.patch_all() monkey.patch_all() # pragma: testrunner-no-monkey-combine
tcurrent2 = threading.current_thread() tcurrent2 = threading.current_thread()
self.assertIsNot(tcurrent, current) self.assertIsNot(tcurrent, current)
# We get a dummy thread now # We get a dummy thread now
......
...@@ -52,6 +52,6 @@ if __name__ == '__main__': ...@@ -52,6 +52,6 @@ if __name__ == '__main__':
# Only patch after we're running # Only patch after we're running
from gevent import monkey from gevent import monkey
monkey.patch_all() monkey.patch_all() # pragma: testrunner-no-monkey-combine
greentest.main() greentest.main()
...@@ -7,7 +7,7 @@ import gevent.testing as greentest ...@@ -7,7 +7,7 @@ import gevent.testing as greentest
script = """ script = """
from gevent import monkey from gevent import monkey
monkey.patch_all() monkey.patch_all() # pragma: testrunner-no-monkey-combine
import sys, os, threading, time import sys, os, threading, time
......
...@@ -142,6 +142,7 @@ class TestTree(greentest.TestCase): ...@@ -142,6 +142,7 @@ class TestTree(greentest.TestCase):
value = re.compile(' fileno=.').sub('', value) value = re.compile(' fileno=.').sub('', value)
value = value.replace('ref=-1', 'ref=0') value = value.replace('ref=-1', 'ref=0')
value = value.replace("type.current_tree", 'GreenletTree.current_tree') value = value.replace("type.current_tree", 'GreenletTree.current_tree')
value = value.replace('gevent.tests.__main__.MyLocal', '__main__.MyLocal')
return value return value
@greentest.ignores_leakcheck @greentest.ignores_leakcheck
......
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