PSMDB-1959 Fix stacktrace tests broken by dev_stacktrace enabled by default#1692
PSMDB-1959 Fix stacktrace tests broken by dev_stacktrace enabled by default#1692
Conversation
…efault When MONGO_CONFIG_DEV_STACKTRACE is defined, printStackTrace() routes to printCppTrace() (cpptrace format) instead of the structured JSON output. Tests that expect structured JSON format were broken. Fix by calling printStructuredStackTrace(StackTraceSink&) directly, bypassing the dev_stacktrace routing, in the three affected call sites: - stacktrace_libunwind_test_functions.cpp: staticFunction (Linkage test) - stacktrace_test.cpp: PosixFormat test lambda - stacktrace_test.cpp: traceString() (EarlyTraceSanity test)
There was a problem hiding this comment.
Pull request overview
This PR fixes stacktrace tests that broke when MONGO_CONFIG_DEV_STACKTRACE was enabled by default. When this config is defined and enabled, printStackTrace() routes to printCppTrace() (cpptrace format) instead of structured JSON output. Tests expecting structured JSON format were failing. The fix ensures these tests call printStructuredStackTrace() directly, bypassing the dev_stacktrace routing.
Changes:
- Modified three test call sites to use
printStructuredStackTrace(sink)instead ofprintStackTrace()to ensure structured JSON output regardless of dev_stacktrace configuration - Added explicit
OstreamStackTraceSinkcreation where previouslyprintStackTrace(os)was called directly with an ostream
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/mongo/util/stacktrace_test.cpp | Fixed PosixFormat test lambda (line 180) and traceString() helper (lines 306-307) to call printStructuredStackTrace() directly with explicit sink creation |
| src/mongo/util/stacktrace_libunwind_test_functions.cpp | Fixed staticFunction() used by Linkage test (lines 44-45) to call printStructuredStackTrace() with explicit sink creation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| OstreamStackTraceSink sink{os}; | ||
| printStructuredStackTrace(sink); |
There was a problem hiding this comment.
The fix correctly bypasses the dev_stacktrace routing by calling printStructuredStackTrace(sink) directly. However, there's an underlying issue in the stacktrace implementation itself: In stacktrace_posix.cpp (line 491) and stacktrace_windows.cpp (line 334), the printStructuredStackTrace(std::ostream& os) overload creates an OstreamStackTraceSink and then calls printStackTrace(sink) instead of printStructuredStackTrace(sink). This defeats the purpose of having a separate printStructuredStackTrace function, as it will still route through the dev_stacktrace logic when MONGO_CONFIG_DEV_STACKTRACE is defined. Those implementations should call printStructuredStackTrace(sink) to be consistent with the intent.
There was a problem hiding this comment.
Yes that is a correct point, however it is out of the context, it requires additional investigation because we don't know why it was implemented this way by MongoDB developers (was it intended when --dev_stacktrace was introduced?).
When MONGO_CONFIG_DEV_STACKTRACE is defined, printStackTrace() routes to printCppTrace() (cpptrace format) instead of the structured JSON output. Tests that expect structured JSON format were broken.
Fix by calling printStructuredStackTrace(StackTraceSink&) directly, bypassing the dev_stacktrace routing, in the three affected call sites: