Skip to content

Commit

Permalink
[Winlogbeat] Retry ReportEvent in tests (elastic#24645)
Browse files Browse the repository at this point in the history
Under Windows 7 and Windows 10, writes to a newly created event log fail occasionally. It seems that there is a delay between when an event log is created and publishing events to it is allowed.
  • Loading branch information
andrewkroh authored Mar 18, 2021
1 parent a2e8969 commit 41ae9ab
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions winlogbeat/tests/system/winlogbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import platform
import sys
import time
import yaml

if sys.platform.startswith("win"):
Expand Down Expand Up @@ -75,8 +76,17 @@ def write_event_log(self, message, eventID=10, sid=None,
if level is None:
level = win32evtlog.EVENTLOG_INFORMATION_TYPE

win32evtlogutil.ReportEvent(source, eventID,
eventType=level, strings=[message], sid=sid)
# Retry on exception for up to 10 sec.
t = time.monotonic()
while True:
try:
win32evtlogutil.ReportEvent(source, eventID,
eventType=level, strings=[message], sid=sid)
break
except:
if time.monotonic() - t < 10:
continue
raise

def get_sid(self):
if self.sid is None:
Expand Down

0 comments on commit 41ae9ab

Please sign in to comment.