Module: check_mk
Branch: master
Commit: 42085da1826499c86de1c424284c6f25f974d5ff
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=42085da1826499…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Thu Jan 11 08:15:27 2018 +0100
Make windows eventlog tests less sensitive
Introduce a tolerance of 10 when verifying the expected eventstate.txt.
Use this tolerance when verifying non-essential event logs (others than
used for actual testing) as some system-dependent log entries may appear
there sporadically in a race condition as we cannot easily turn reading
both the eventlog and eventstate.txt into an atomic operation. When
verifying the Application log actually used for testing, allow no
tolerance (that is, use tolerance = 0). Even if not 100% secure, race
conditions are far less probable in Application log.
Change-Id: I27866c6554ebfebbfbb7b3de3fdfc936b414c59c
---
agents/windows/it/test_section_eventlog.py | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/agents/windows/it/test_section_eventlog.py
b/agents/windows/it/test_section_eventlog.py
index 01af8c1..c7c02b1 100644
--- a/agents/windows/it/test_section_eventlog.py
+++ b/agents/windows/it/test_section_eventlog.py
@@ -1,5 +1,6 @@
import contextlib
from itertools import chain, repeat
+import math
import os
import platform
import re
@@ -23,6 +24,7 @@ testlog = 'Application'
testsource = 'Test source'
testeventtype = 'Warning'
testdescription = 'Something might happen!'
+tolerance = 10
testids = range(1, 3)
@@ -171,9 +173,12 @@ def verify_eventstate():
sorted(expected_eventstate.items()),
sorted(actual_eventstate.items())):
assert expected_log == actual_log
- assert expected_state == actual_state, (
- "expected state for log '%s' is %d, actual state %d" %
- (expected_log, expected_state, actual_state))
+ state_tolerance = 0 if expected_log == testlog else tolerance
+ assert math.fabs(
+ expected_state - actual_state) <= state_tolerance, (
+ "expected state for log '%s' is %d, actual state %d,
"
+ "state_tolerance %d" % (expected_log, expected_state,
+ actual_state, state_tolerance))
@pytest.mark.usefixtures("no_statefile")