Skip to content

fix(test): run the logger case without PlatformInit - #369

Merged
Jiu-xiao merged 1 commit into
devfrom
fix/test-logger-20261119
Nov 19, 2026
Merged

Jiu-xiao merged 1 commit into
devfrom
fix/test-logger-20261119

Conversation

@Jiu-xiao

Copy link
Copy Markdown
Member

Summary

test_logger.cpp:91 (CountSubstring(text, "\r\n") == 3) failed intermittently when libxr_test ran with a non-TTY stdin.

Cause. The isolated logger case ran PlatformInit(), which starts the STDIO.read_ thread. When stdin is not a TTY, StdiThread logs XR_LOG_WARN("STDIO.read_: stdin is not a TTY, parking thread forever") asynchronously (system/linux/libxr_system.cpp:57). If that happened while the test had STDIO::write_ swapped to its Pipe, the warning line landed in the captured text and the count became 4. CI does not hit this because ctest starts libxr_test under script, so stdin is a TTY.

Fix. The case needs no STDIO workers: Logger initializes lazily and the test owns the writer. It now runs isolated with platform_init = false, like linux_database_raw and linux_shm_topic. The platform_init field comment and the test comment say why.

Test-only change; no product code touched.

Verification

On the Ubuntu 24 build host:

  • Before (dev 326ae1d28), libxr_test --direct-case logger </dev/null with 14 busy loops: 4 failures in 400 runs. In every failing run the warning was missing from stdout, so it had gone into the Pipe. With a TTY stdin (script): 0 failures in 150 runs.
  • After, same load: 0 failures in 1000 runs. Full libxr_test </dev/null: 0 failures in 25 runs.
  • ctest (Debug/ON, Release/ON, Release/OFF, LIBXR_TEST_BUILD=ON): 10/10 (test_linux_can skipped), 0 warnings.
  • git diff --check origin/dev..HEAD: clean.

Not changed

STDIO::write_ is a plain pointer read without the mutex in OnLogMessage and BeginWriteSession, and STDIO::write_mutex_ is created lazily without synchronization. This change keeps the logger case away from that race but does not fix it.

The isolated logger case ran PlatformInit(), which starts the STDIO read
thread. When stdin is not a TTY that thread logs "stdin is not a TTY,
parking thread forever" asynchronously, and the line could land in the Pipe
the test had swapped into STDIO::write_, so the "\r\n" count became 4.

The case needs no STDIO workers (Logger initializes lazily and the test owns
the writer), so it now skips PlatformInit like the other isolated cases that
need no platform threads.
@greptile-apps

greptile-apps Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] This appears safe to merge; the change removes the unwanted worker without changing the output checks.

Summary

The isolated logger test now skips PlatformInit, preventing STDIO startup warnings from entering its captured output. No actionable issues found.

  • The logger test captures output without starting STDIO workers.

Reviews (1) · Last reviewed commit: "fix(test): run the logger case without P..." · Reviewed by Greptile

@Jiu-xiao
Jiu-xiao merged commit c841502 into dev Nov 19, 2026
8 checks passed
@Jiu-xiao
Jiu-xiao deleted the fix/test-logger-20261119 branch November 19, 2026 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant