mirror of https://github.com/fail2ban/fail2ban
coverage: testErrorsInLoop should avoid sporadic coverage changes, if some communication errors not occurred sometimes.
parent
a1fd2c507e
commit
80932af406
|
@ -122,7 +122,9 @@ def loop(active, timeout=None, use_poll=False):
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
timeout = Utils.DEFAULT_SLEEP_TIME
|
timeout = Utils.DEFAULT_SLEEP_TIME
|
||||||
poll = asyncore.poll
|
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')
|
logSys.debug('Server listener (select) uses poll')
|
||||||
# poll2 expected a timeout in milliseconds (but poll and loop in seconds):
|
# poll2 expected a timeout in milliseconds (but poll and loop in seconds):
|
||||||
timeout = float(timeout) / 1000
|
timeout = float(timeout) / 1000
|
||||||
|
|
|
@ -31,8 +31,10 @@ import threading
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from .utils import LogCaptureTestCase
|
||||||
|
|
||||||
from .. import protocol
|
from .. import protocol
|
||||||
from ..server.asyncserver import AsyncServer, AsyncServerException
|
from ..server.asyncserver import AsyncServer, AsyncServerException, loop
|
||||||
from ..server.utils import Utils
|
from ..server.utils import Utils
|
||||||
from ..client.csocket import CSocket
|
from ..client.csocket import CSocket
|
||||||
|
|
||||||
|
@ -126,7 +128,20 @@ class Socket(unittest.TestCase):
|
||||||
self.assertFalse(os.path.exists(self.sock_name))
|
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):
|
def testPrintFormattedAndWiki(self):
|
||||||
# redirect stdout to devnull
|
# redirect stdout to devnull
|
||||||
|
|
Loading…
Reference in New Issue