mirror of https://github.com/fail2ban/fail2ban
coverage: fix another sporadic coverage decrease, if idle mode never reached in some test-cases (e. g. by slowly reloading of jails).
parent
80932af406
commit
a10d544ddc
|
@ -276,8 +276,10 @@ class Actions(JailThread, Mapping):
|
||||||
exc_info=logSys.getEffectiveLevel()<=logging.DEBUG)
|
exc_info=logSys.getEffectiveLevel()<=logging.DEBUG)
|
||||||
while self.active:
|
while self.active:
|
||||||
if self.idle:
|
if self.idle:
|
||||||
|
logSys.debug("Actions: enter idle mode")
|
||||||
Utils.wait_for(lambda: not self.active or not self.idle,
|
Utils.wait_for(lambda: not self.active or not self.idle,
|
||||||
self.sleeptime * 10, self.sleeptime)
|
lambda: False, self.sleeptime)
|
||||||
|
logSys.debug("Actions: leave idle mode")
|
||||||
continue
|
continue
|
||||||
if not Utils.wait_for(lambda: not self.active or self.__checkBan(), self.sleeptime):
|
if not Utils.wait_for(lambda: not self.active or self.__checkBan(), self.sleeptime):
|
||||||
self.__checkUnBan()
|
self.__checkUnBan()
|
||||||
|
|
|
@ -30,9 +30,10 @@ import time
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from ..server.action import CommandAction, CallingMap, substituteRecursiveTags
|
from ..server.action import CommandAction, CallingMap, substituteRecursiveTags
|
||||||
from ..server.actions import OrderedDict
|
from ..server.actions import OrderedDict, Actions
|
||||||
from ..server.utils import Utils
|
from ..server.utils import Utils
|
||||||
|
|
||||||
|
from .dummyjail import DummyJail
|
||||||
from .utils import LogCaptureTestCase
|
from .utils import LogCaptureTestCase
|
||||||
from .utils import pid_exists
|
from .utils import pid_exists
|
||||||
|
|
||||||
|
@ -568,3 +569,19 @@ class CommandActionTest(LogCaptureTestCase):
|
||||||
self.assertIn("'b': 11", s)
|
self.assertIn("'b': 11", s)
|
||||||
self.assertIn("'c': ", s) # presents as callable
|
self.assertIn("'c': ", s) # presents as callable
|
||||||
self.assertNotIn("'c': ''", s) # but not empty
|
self.assertNotIn("'c': ''", s) # but not empty
|
||||||
|
|
||||||
|
def testActionsIdleMode(self):
|
||||||
|
a = Actions(DummyJail())
|
||||||
|
a.sleeptime = 0.0001; # don't need to wait long
|
||||||
|
# enter idle mode right now (start idle):
|
||||||
|
a.idle = True;
|
||||||
|
# start:
|
||||||
|
a.start()
|
||||||
|
# wait for enter/leave of idle mode:
|
||||||
|
self.assertLogged("Actions: enter idle mode", wait=10)
|
||||||
|
# leave idle mode:
|
||||||
|
a.idle = False
|
||||||
|
self.assertLogged("Actions: leave idle mode", wait=10)
|
||||||
|
# stop it:
|
||||||
|
a.active = False
|
||||||
|
a.join()
|
Loading…
Reference in New Issue