Skip to content

Commit afeb105

Browse files
committed
Fix for delaying logging with timeouts.
Previous messages weren't restored meaning that messages could be lost. The unused variable also made linters unhappy. This code attemps to avoid problems with timeouts interrupting writing to output files. The current code was written to fix #5395 and is basically a rewrite of the fix for #2839. As #5417 explains, there are still problems and bigger changes are needed.
1 parent e96e62a commit afeb105

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

atest/robot/standard_libraries/builtin/used_in_custom_libs_and_listeners.robot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Use BuiltIn keywords with timeouts
2929
Check Log Message ${tc[3, 0, 1]} 42
3030
Check Log Message ${tc[3, 1, 0]} Test timeout 1 day active. * seconds left. level=DEBUG pattern=True
3131
Check Log Message ${tc[3, 1, 1]} \xff
32+
# This message is in wrong place due to it being delayed and child keywords being logged first.
33+
# It should be in position [3, 0], not [3, 2].
34+
Check Log Message ${tc[3, 2]} Test timeout 1 day active. * seconds left. level=DEBUG pattern=True
3235

3336
User keyword used via 'Run Keyword'
3437
${tc} = Check Test Case ${TESTNAME}

src/robot/output/outputfile.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ def _get_logger(self, path, rpa, legacy_output):
5353
@property
5454
@contextmanager
5555
def delayed_logging(self):
56-
self._delayed_messages, prev_messages = [], self._delayed_messages
56+
self._delayed_messages, previous = [], self._delayed_messages
5757
try:
5858
yield
5959
finally:
60-
self._delayed_messages, messages = None, self._delayed_messages
61-
for msg in messages or ():
62-
self.log_message(msg)
60+
self._delayed_messages, messages = previous, self._delayed_messages
61+
for msg in messages:
62+
self.log_message(msg, no_delay=True)
6363

6464
def start_suite(self, data, result):
6565
self.logger.start_suite(result)
@@ -170,14 +170,15 @@ def start_error(self, data, result):
170170
def end_error(self, data, result):
171171
self.logger.end_error(result)
172172

173-
def log_message(self, message):
173+
def log_message(self, message, no_delay=False):
174174
if self.is_logged(message):
175-
if self._delayed_messages is None:
175+
if self._delayed_messages is None or no_delay:
176176
# Use the real logger also when flattening.
177177
self.real_logger.message(message)
178178
else:
179-
# Logging is delayed when using timeouts to avoid timeouts
180-
# killing output writing that could corrupt the output.
179+
# Logging is delayed when using timeouts to avoid writing to output
180+
# files being interrupted. There are still problems, though:
181+
# https://github.com/robotframework/robotframework/issues/5417
181182
self._delayed_messages.append(message)
182183

183184
def message(self, message):

0 commit comments

Comments
 (0)