fix: make the test log handler coexist with rosout#656
Open
azerupi wants to merge 1 commit into
Open
Conversation
The test-only custom logging output handler (`set_logging_output_handler`, used by the rclrs logging tests) installed itself via `rcutils_logging_set_output_handler`, *replacing* the default `rcl_logging_multiple_output_handler`. While installed this had two process-global side effects: - /rosout (and console/file) publishing was disabled, because the default handler that fans out to them was no longer called. A test running concurrently that relied on /rosout (e.g. the rosout publishing test) could silently lose its messages. - Every log record emitted anywhere in the process was captured into the handler's buffer, so concurrent tests' logs polluted assertions such as `last_message()`. Under cargo's parallel test execution these made the logging tests intermittently fail. Fix: the custom handler now - chains to `rcl_logging_multiple_output_handler`, so console/file/rosout keep working while it is installed, and - captures only records emitted on the thread that installed it (the test thread), so concurrently-running tests no longer pollute the captured output. To keep the forwarded record printf-safe, `impl_log` now always calls `rcutils_log` with the `"%s"` + message form (instead of passing the message as the format string) and stashes the finished message in a thread-local that the handler reads back. This avoids parsing the C `va_list` in Rust while letting the record be forwarded to the default handler unchanged. All changes are within `#[cfg(test)]` code; production logging is unchanged.
This was referenced Jun 27, 2026
maspe36
reviewed
Jul 4, 2026
Comment on lines
+270
to
+271
| // process-wide for the duration — breaking concurrently-running tests that | ||
| // rely on `/rosout`. The format string and `va_list` are passed through |
Collaborator
There was a problem hiding this comment.
This change seems fine in of itself,
breaking concurrently-running tests that rely on
/rosout
but to me this is the real issue. Unit tests that depend on system level properties are actually integration tests and I argue shouldn't be run concurrently.
Do you have a list of these tests that would break concurrently?
Contributor
Author
There was a problem hiding this comment.
I believe it is only test_logging_macros because it replaces the logging out handler by calling set_logging_output_handler and this then intermittently breaks the other tests that subscribe to /rosout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The test-only custom logging output handler (
set_logging_output_handler, used by the rclrs logging tests) installed itself viarcutils_logging_set_output_handler, replacing the defaultrcl_logging_multiple_output_handler. While installed this had two process-global side effects:/rosout(and console/file) publishing was disabled, because the default handler that fans out to them was no longer called. A test running concurrently that relied on/rosout(e.g. the rosout publishing test) could silently lose its messages.last_message().Under cargo's parallel test execution these made the logging tests intermittently fail.
Fix: the custom handler now
rcl_logging_multiple_output_handler, so console/file/rosout keep working while it is installed, andTo keep the forwarded record printf-safe,
impl_lognow always callsrcutils_logwith the"%s"+ message form (instead of passing the message as the format string) and stashes the finished message in a thread-local that the handler reads back. This avoids parsing the Cva_listin Rust while letting the record be forwarded to the default handler unchanged.All changes are within
#[cfg(test)]code, production logging is unchanged.