Commit a9842bca authored by Jason Madden's avatar Jason Madden

Apply logging updates to test__socket_dns as well.

parent 007a8a50
......@@ -37,24 +37,26 @@ class Popen(subprocess.Popen):
_colorscheme = {
'normal': 'normal',
'default': 'default',
'info': 'normal',
'actual-output': 'red',
'character-diffs': 'magenta',
'debug': 'cyan',
'suboptimal-behaviour': 'magenta',
'diff-chunk': 'magenta',
'error': 'brightred',
'number': 'green',
'slow-test': 'brightmagenta',
'ok-number': 'green',
'error-number': 'brightred',
'exception': 'red',
'expected-output': 'green',
'failed-example': 'cyan',
'filename': 'lightblue',
'info': 'normal',
'lineno': 'lightred',
'testname': 'lightcyan',
'failed-example': 'cyan',
'expected-output': 'green',
'actual-output': 'red',
'character-diffs': 'magenta',
'diff-chunk': 'magenta',
'exception': 'red',
'number': 'green',
'ok-number': 'green',
'skipped': 'brightyellow',
'slow-test': 'brightmagenta',
'suboptimal-behaviour': 'magenta',
'testname': 'lightcyan',
'warning': 'cyan',
}
_prefixes = [
......
......@@ -6,20 +6,24 @@ from gevent import monkey
import os
import re
import gevent.testing as greentest
import unittest
import socket
from time import time
import traceback
import gevent.socket as gevent_socket
from gevent.testing.util import log
import gevent.testing as greentest
#from gevent.testing.util import log
#from gevent.testing.util import debug
from gevent.testing import util
from gevent.testing import six
from gevent.testing.six import xrange
from gevent.testing import flaky
resolver = gevent.get_hub().resolver
log('Resolver: %s', resolver)
util.debug('Resolver: %s', resolver)
if getattr(resolver, 'pool', None) is not None:
resolver.pool.size = 1
......@@ -33,8 +37,11 @@ import gevent.testing.timing
assert gevent_socket.gaierror is socket.gaierror
assert gevent_socket.error is socket.error
DEBUG = os.getenv('GEVENT_DEBUG', '') == 'trace'
TRACE = not util.QUIET and os.getenv('GEVENT_DEBUG', '') == 'trace'
def trace(message, *args, **kwargs):
if TRACE:
util.debug(message, *args, **kwargs)
def _run(function, *args):
try:
......@@ -42,7 +49,7 @@ def _run(function, *args):
assert not isinstance(result, BaseException), repr(result)
return result
except Exception as ex:
if DEBUG:
if TRACE:
traceback.print_exc()
return ex
......@@ -59,7 +66,9 @@ def format_call(function, args):
return function + args
def log_fresult(result, seconds):
def trace_fresult(result, seconds):
if not TRACE:
return
if isinstance(result, Exception):
msg = ' -=> raised %r' % (result, )
else:
......@@ -70,23 +79,21 @@ def log_fresult(result, seconds):
space = ' ' * space
else:
space = ''
log(msg + space + time_ms)
util.debug(msg + space + time_ms)
def run(function, *args):
if DEBUG:
log(format_call(function, args))
trace(format_call(function, args))
delta = time()
result = _run(function, *args)
delta = time() - delta
if DEBUG:
log_fresult(result, delta)
trace_fresult(result, delta)
return result, delta
def log_call(result, runtime, function, *args):
log(format_call(function, args))
log_fresult(result, runtime)
def trace_call(result, runtime, function, *args):
util.debug(format_call(function, args))
trace_fresult(result, runtime)
def compare_relaxed(a, b):
......@@ -223,7 +230,7 @@ class TestCase(greentest.TestCase):
__timeout__ = 30
switch_expected = None
verbose_dns = False
verbose_dns = TRACE
def setUp(self):
super(TestCase, self).setUp()
......@@ -253,10 +260,10 @@ class TestCase(greentest.TestCase):
real_func = monkey.get_original('socket', func)
real_result, time_real = run(real_func, *args)
gevent_result, time_gevent = run(gevent_func, *args)
if not DEBUG and self.should_log_results(real_result, gevent_result):
log('')
log_call(real_result, time_real, real_func, *args)
log_call(gevent_result, time_gevent, gevent_func, *args)
if util.QUIET and self.should_log_results(real_result, gevent_result):
util.log('')
trace_call(real_result, time_real, real_func, *args)
trace_call(gevent_result, time_gevent, gevent_func, *args)
self.assertEqualResults(real_result, gevent_result, func)
if self.verbose_dns and time_gevent > time_real + 0.01 and time_gevent > 0.02:
......@@ -267,7 +274,7 @@ class TestCase(greentest.TestCase):
else:
word = 'quite'
log('\nWARNING: %s slow: %s', word, msg)
util.log('\nWARNING: %s slow: %s', word, msg, color='warning')
return gevent_result
......@@ -332,7 +339,9 @@ class TestCase(greentest.TestCase):
errors = (socket.gaierror, socket.herror, TypeError)
if isinstance(real_result, errors) and isinstance(gevent_result, errors):
if type(real_result) is not type(gevent_result):
log('WARNING: error type mismatch: %r (gevent) != %r (stdlib)', gevent_result, real_result)
util.log('WARNING: error type mismatch: %r (gevent) != %r (stdlib)',
gevent_result, real_result,
color='warning')
return
real_result = self._normalize_result(real_result, func)
......@@ -486,7 +495,7 @@ class TestEtcHosts(TestCase):
hf = SanitizedHostsFile(os.path.join(os.path.dirname(__file__),
'hosts_file.txt'))
all_etc_hosts = sorted(hf.iter_all_host_addr_pairs())
if len(all_etc_hosts) > cls.MAX_HOSTS and not DEBUG:
if len(all_etc_hosts) > cls.MAX_HOSTS and util.QUIET:
all_etc_hosts = all_etc_hosts[:cls.MAX_HOSTS]
for host, ip in all_etc_hosts:
......
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