mirror of https://github.com/fail2ban/fail2ban
observer fix: wait it becomes idle in reload test case (complete writing of failures to database);
parent
8e2711681c
commit
0636b3247d
|
@ -413,7 +413,7 @@ class ObserverThread(JailThread):
|
|||
"""
|
||||
# check jail active :
|
||||
if not jail.isAlive() or not jail.database:
|
||||
return
|
||||
return banTime
|
||||
be = jail.getBanTimeExtra()
|
||||
ip = ticket.getIP()
|
||||
orgBanTime = banTime
|
||||
|
|
|
@ -172,6 +172,10 @@ class Server:
|
|||
logSys.info("Exiting Fail2ban")
|
||||
|
||||
def quit(self):
|
||||
# Give observer a small chance to complete its work before exit
|
||||
if Observers.Main is not None:
|
||||
Observers.Main.stop()
|
||||
|
||||
# Stop communication first because if jail's unban action
|
||||
# tries to communicate via fail2ban-client we get a lockup
|
||||
# among threads. So the simplest resolution is to stop all
|
||||
|
|
|
@ -81,6 +81,14 @@ fail2banserver.output = \
|
|||
protocol.output = _test_output
|
||||
|
||||
|
||||
Observers = server.Observers
|
||||
|
||||
def _observer_wait_idle():
|
||||
"""Helper to wait observer becomes idle"""
|
||||
if Observers.Main is not None:
|
||||
Observers.Main.wait_empty(MID_WAITTIME)
|
||||
Observers.Main.wait_idle(MID_WAITTIME / 5)
|
||||
|
||||
#
|
||||
# Mocking .exit so we could test its correct operation.
|
||||
# Two custom exceptions will be assessed to be raised in the tests
|
||||
|
@ -934,6 +942,8 @@ class Fail2banServerTest(Fail2banClientServerBase):
|
|||
"[test-jail2] Found 192.0.2.3",
|
||||
"[test-jail2] Ban 192.0.2.3",
|
||||
all=True)
|
||||
# if observer available wait for it becomes idle (write all tickets to db):
|
||||
_observer_wait_idle()
|
||||
|
||||
# rotate logs:
|
||||
_write_file(test1log, "w+")
|
||||
|
|
Loading…
Reference in New Issue