Skip to content

Commit 735eda8

Browse files
gaogaotiantianzhengruifeng
authored andcommitted
[SPARK-54874][TESTS][INFRA] Avoid interleave failed test logs with test outputs
### What changes were proposed in this pull request? 1. `FAILURE_REPORTING_LOCK` is only for the unified logger file, we don't need that for `per_test_output` 2. Use `LOGGER` instead of `print` to print data because `LOGGER` has an internal lock to avoid interleave 3. Put all the lines together and print it once to avoid interleave ### Why are the changes needed? We have a thread pool to run different individual tests and the test output is interleaved with error messages. https://github.com/apache/spark/actions/runs/20594052053/job/59144974177 It's difficult to tell which test the debugging message belongs to. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Locally it works ### Was this patch authored or co-authored using generative AI tooling? No Closes #53648 from gaogaotiantian/avoid-interleave-logs. Authored-by: Tian Gao <[email protected]> Signed-off-by: Ruifeng Zheng <[email protected]>
1 parent 1fc6ff2 commit 735eda8

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

python/run-tests.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,21 @@ def run_individual_python_test(target_dir, test_name, pyspark_python, keep_test_
301301
# Exit on the first failure but exclude the code 5 for no test ran, see SPARK-46801.
302302
if retcode != 0 and retcode != 5:
303303
try:
304+
per_test_output.seek(0)
304305
with FAILURE_REPORTING_LOCK:
305306
with open(LOG_FILE, 'ab') as log_file:
306-
per_test_output.seek(0)
307307
log_file.writelines(per_test_output)
308-
per_test_output.seek(0)
309-
for line in per_test_output:
310-
decoded_line = line.decode("utf-8", "replace")
311-
if not re.match('[0-9]+', decoded_line):
312-
print(decoded_line, end='')
313-
per_test_output.close()
308+
309+
# We don't want the logging lines interleave with the test output, so we read the
310+
# full file and output with LOGGER which has internal locking.
311+
per_test_output.seek(0)
312+
lines = []
313+
for line in per_test_output:
314+
line = line.decode("utf-8", "replace")
315+
if not re.match('[0-9]+', line):
316+
lines.append(line)
317+
LOGGER.error(f"{test_name} with {pyspark_python} failed:\n{''.join(lines)}")
318+
per_test_output.close()
314319
except BaseException:
315320
LOGGER.exception("Got an exception while trying to print failed test output")
316321
finally:

0 commit comments

Comments
 (0)