coverage: testErrorsInLoop should avoid sporadic coverage changes, if some communication errors not occurred sometimes.

pull/2005/head
sebres 7 years ago
parent a1fd2c507e
commit 80932af406

@ -122,7 +122,9 @@ def loop(active, timeout=None, use_poll=False):
if timeout is None:
timeout = Utils.DEFAULT_SLEEP_TIME
poll = asyncore.poll
if use_poll and asyncore.poll2 and hasattr(asyncore.select, 'poll'): # pragma: no cover
if callable(use_poll):
poll = use_poll
elif use_poll and asyncore.poll2 and hasattr(asyncore.select, 'poll'): # pragma: no cover
logSys.debug('Server listener (select) uses poll')
# poll2 expected a timeout in milliseconds (but poll and loop in seconds):
timeout = float(timeout) / 1000

@ -31,8 +31,10 @@ import threading
import time
import unittest
from .utils import LogCaptureTestCase
from .. import protocol
from ..server.asyncserver import AsyncServer, AsyncServerException
from ..server.asyncserver import AsyncServer, AsyncServerException, loop
from ..server.utils import Utils
from ..client.csocket import CSocket
@ -126,7 +128,20 @@ class Socket(unittest.TestCase):
self.assertFalse(os.path.exists(self.sock_name))
class ClientMisc(unittest.TestCase):
class ClientMisc(LogCaptureTestCase):
def testErrorsInLoop(self):
phase = {'cntr': 0}
def _active():
return phase['cntr'] < 40
def _poll(*args):
phase['cntr'] += 1
raise Exception('test *%d*' % phase['cntr'])
# test errors "catched" and logged:
loop(_active, use_poll=_poll)
self.assertLogged("test *1*", "test *10*", "test *20*", all=True)
self.assertLogged("Too many errors - stop logging connection errors")
self.assertNotLogged("test *21*", "test *22*", "test *23*", all=True)
def testPrintFormattedAndWiki(self):
# redirect stdout to devnull

Loading…
Cancel
Save