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
from .exception import ExpectedException
class QuietHub(Hub):
_resolver = None
_threadpool = None
EXPECTED_TEST_ERROR = (ExpectedException,)
......@@ -42,3 +44,6 @@ class QuietHub(Hub):
# see handle_error
return
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 += [
'test_ssl.BasicSocketTests.test_openssl_version'
]
if TRAVIS and OSX:
if OSX:
disabled_tests += [
# This sometimes produces OSError: Errno 40: Message too long
......
This diff is collapsed.
......@@ -29,7 +29,8 @@ class TestTimeout(greentest.TestCase):
while True:
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,
udp_port=address[-1])
......
......@@ -158,4 +158,4 @@ class Test(greentest.TestCase):
if __name__ == '__main__':
greentest.main()
greentest.main() # pragma: testrunner-no-combine
......@@ -7,18 +7,25 @@ try:
except ImportError:
import _thread as thread
from gevent import testing as greentest
hub = gevent.get_hub()
watcher = hub.loop.async_()
class Test(greentest.TestCase):
def test(self):
hub = gevent.get_hub()
watcher = hub.loop.async_()
# BWC for <3.7: This should still be an attribute
assert hasattr(hub.loop, 'async')
# BWC for <3.7: This should still be an attribute
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
hub.wait(watcher)
with gevent.Timeout(1.0): # Large timeout for appveyor
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
from gevent.hub import get_hub
called = []
from gevent import testing as greentest
class Test(greentest.TestCase):
def f():
called.append(1)
def test(self):
loop = get_hub().loop
called = []
def f():
called.append(1)
def main():
loop = get_hub().loop
x = loop.run_callback(f)
x = loop.run_callback(f)
assert x, x
gevent.sleep(0)
assert called == [1], called
assert not x, (x, bool(x))
assert x, x
gevent.sleep(0)
assert called == [1], called
assert not x, (x, bool(x))
x = loop.run_callback(f)
assert x, x
x.stop()
assert not x, x
gevent.sleep(0)
assert called == [1], called
assert not x, x
x = loop.run_callback(f)
assert x, x
x.stop()
assert not x, x
gevent.sleep(0)
assert called == [1], called
assert not x, x
if __name__ == '__main__':
called[:] = []
main()
greentest.main()
......@@ -48,4 +48,4 @@ class TestDestroyHub(unittest.TestCase):
hub.destroy()
if __name__ == '__main__':
unittest.main()
unittest.main() # pragma: testrunner-no-combine
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 socket
......
from gevent import monkey
monkey.patch_all(subprocess=True)
monkey.patch_all()
from gevent.server import DatagramServer
......
......@@ -21,7 +21,8 @@ import sys
import gevent
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 skipOnPyPy
from gevent.testing import params
......@@ -142,4 +143,4 @@ class TestGreenIo(TestCase):
if __name__ == '__main__':
main()
greentest.main()
import gevent
from gevent import testing as greentest
def func():
pass
class Test(greentest.TestCase):
a = gevent.spawn(func)
b = gevent.spawn(func)
gevent.joinall([a, b, a])
def test(self):
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():
global count
count += 1
loop = get_hub().loop
loop.run_callback(incr)
loop.run()
self.assertEqual(count, [1])
loop = loop()
loop.run_callback(incr)
loop.run()
assert count == 1, count
if __name__ == '__main__':
greentest.main()
import sys
import unittest
from gevent.testing import TestCase, main
from gevent.testing import TestCase
import gevent
from gevent.timeout import Timeout
......@@ -53,4 +53,4 @@ class TestQueue(TestCase): # pragma: no cover
if __name__ == '__main__':
main()
unittest.main()
from subprocess import Popen
from gevent import monkey
monkey.patch_all()
......@@ -79,6 +77,7 @@ class TestMonkey(SubscriberCleanupMixin, unittest.TestCase):
self.assertTrue(monkey.is_object_patched(modname, objname))
def test_patch_subprocess_twice(self):
Popen = monkey.get_original('subprocess', 'Popen')
self.assertNotIn('gevent', repr(Popen))
self.assertIs(Popen, monkey.get_original('subprocess', 'Popen'))
monkey.patch_subprocess()
......
......@@ -22,7 +22,7 @@ from __future__ import print_function
from gevent import monkey
monkey.patch_all(thread=False)
monkey.patch_all()
from contextlib import contextmanager
try:
......
import unittest
import gevent.testing as greentest
from gevent.testing import TestCase, main
from gevent.testing import TestCase
import gevent
from gevent.hub import get_hub, LoopExit
from gevent import util
......@@ -462,4 +462,4 @@ del AbstractGenericGetTestCase
if __name__ == '__main__':
main()
greentest.main()
......@@ -6,24 +6,29 @@ Fails with PyPy 2.2.1
"""
from __future__ import print_function
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():
result.append(repr(sys.exc_info()))
def func():
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):
conn.close()
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):
self.Settings.assert500(self)
......
......@@ -49,7 +49,7 @@ class Thread(_Thread):
class TestTCP(greentest.TestCase):
maxDiff = None
__timeout__ = None
TIMEOUT_ERROR = socket.timeout
long_data = ", ".join([str(x) for x in range(20000)])
......@@ -210,7 +210,9 @@ class TestTCP(greentest.TestCase):
if match_data is None:
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):
self._test_sendall(self.long_data)
......
"""
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
# check that the locks initialized by 'threading' did not init the hub
......
......@@ -3,7 +3,7 @@
import threading
from gevent import monkey
monkey.patch_all()
monkey.patch_all() # pragma: testrunner-no-monkey-combine
import gevent.testing as greentest
......
......@@ -5,4 +5,4 @@ import threading
# in python code, this used to throw RuntimeErro("Cannot release un-acquired lock")
# See https://github.com/gevent/gevent/issues/615
with threading.RLock():
monkey.patch_all()
monkey.patch_all() # pragma: testrunner-no-monkey-combine
......@@ -25,7 +25,7 @@ class Test(greentest.TestCase):
def target():
tcurrent = threading.current_thread()
monkey.patch_all()
monkey.patch_all() # pragma: testrunner-no-monkey-combine
tcurrent2 = threading.current_thread()
self.assertIsNot(tcurrent, current)
# We get a dummy thread now
......
......@@ -52,6 +52,6 @@ if __name__ == '__main__':
# Only patch after we're running
from gevent import monkey
monkey.patch_all()
monkey.patch_all() # pragma: testrunner-no-monkey-combine
greentest.main()
......@@ -7,7 +7,7 @@ import gevent.testing as greentest
script = """
from gevent import monkey
monkey.patch_all()
monkey.patch_all() # pragma: testrunner-no-monkey-combine
import sys, os, threading, time
......
......@@ -142,6 +142,7 @@ class TestTree(greentest.TestCase):
value = re.compile(' fileno=.').sub('', value)
value = value.replace('ref=-1', 'ref=0')
value = value.replace("type.current_tree", 'GreenletTree.current_tree')
value = value.replace('gevent.tests.__main__.MyLocal', '__main__.MyLocal')
return value
@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