fixed sporadically test cases assertion error "AssertionError: 3 != 4" - because multi-threaded, occurred if getFailTicket() called after 3th failure (before 4th failure was monitored), so we will wait in new method waitFailTotal (instead of isFilled) for expected failure count...

pull/1515/head
sebres 2016-08-17 13:40:29 +02:00
parent e3f4ea7284
commit 7b7d60c486
1 changed files with 12 additions and 1 deletions

View File

@ -912,6 +912,7 @@ def get_monitor_failures_journal_testcase(Filter_): # pragma: systemd no cover
self.test_file = os.path.join(TEST_FILES_DIR, "testcase-journal.log") self.test_file = os.path.join(TEST_FILES_DIR, "testcase-journal.log")
self.jail = DummyJail() self.jail = DummyJail()
self.filter = Filter_(self.jail) self.filter = Filter_(self.jail)
self._failTotal = 0
# UUID used to ensure that only meeages generated # UUID used to ensure that only meeages generated
# as part of this test are picked up by the filter # as part of this test are picked up by the filter
self.test_uuid = str(uuid.uuid4()) self.test_uuid = str(uuid.uuid4())
@ -939,6 +940,15 @@ def get_monitor_failures_journal_testcase(Filter_): # pragma: systemd no cover
return "MonitorJournalFailures%s(%s)" \ return "MonitorJournalFailures%s(%s)" \
% (Filter_, hasattr(self, 'name') and self.name or 'tempfile') % (Filter_, hasattr(self, 'name') and self.name or 'tempfile')
def waitFailTotal(self, count, delay=1.):
"""Wait up to `delay` sec to assure that expected failure `count` reached
"""
ret = Utils.wait_for(
lambda: self.filter.failManager.getFailTotal() >= self._failTotal + count and self.jail.isFilled(),
_maxWaitTime(delay))
self._failTotal += count
return ret
def isFilled(self, delay=1.): def isFilled(self, delay=1.):
"""Wait up to `delay` sec to assure that it was modified or not """Wait up to `delay` sec to assure that it was modified or not
""" """
@ -949,8 +959,9 @@ def get_monitor_failures_journal_testcase(Filter_): # pragma: systemd no cover
return Utils.wait_for(self.jail.isEmpty, _maxWaitTime(delay)) return Utils.wait_for(self.jail.isEmpty, _maxWaitTime(delay))
def assert_correct_ban(self, test_ip, test_attempts): def assert_correct_ban(self, test_ip, test_attempts):
self.assertTrue(self.isFilled(_maxWaitTime(10))) # give Filter a chance to react self.assertTrue(self.waitFailTotal(test_attempts, 10)) # give Filter a chance to react
ticket = self.jail.getFailTicket() ticket = self.jail.getFailTicket()
self.assertTrue(ticket)
attempts = ticket.getAttempt() attempts = ticket.getAttempt()
ip = ticket.getIP() ip = ticket.getIP()