Repository navigation
fix(tests): move category assertions into guards to prevent log event ordering races - #354
Merged
0xB10C merged 2 commits intoFeb 12, 2026
Conversation
Move LogDebugCategory::Net assertions from inside the match body into the if-let guard condition so events with the wrong category are skipped rather than matching and failing the assertion. Avoids race conditions with logging order! Fixes/addresses: Issue peer-observer#338 peer-observer#338
Document the purpose and internal steps of check(), spawn_pipe(), setup_node(), and setup_two_connected_nodes() to make the test infrastructure easier to understand for new contributors.
deadmanoz
force-pushed
the
feature/improve-integration-tests
branch
from
February 11, 2026 06:01
bd1ad43 to
164e279
Compare
0xB10C
reviewed
Feb 12, 2026
| /// - node2 connects to node1. | ||
| /// | ||
| /// `node1_args` are appended as extra `bitcoind` CLI flags (e.g. `-debug=validation`) so tests | ||
| /// can enable the specific logging needed to trigger the events they want to observe. |
Collaborator
There was a problem hiding this comment.
mini nit: I think /// are meant for documenting public (i.e. pub) functions that will end up in documentation. As these are private and only test specific, // should do the trick here too. But fine as is.
Collaborator
|
Thank you! One step closer to no tests failing intermittently! |
Collaborator
Author
|
Got another fix incoming 😬 |
deadmanoz
added a commit
to deadmanoz/peer-observer
that referenced
this pull request
Feb 24, 2026
Bitcoin Core's LogError()/LogWarning() emit lines like `[error] AcceptBlock: ...` where `[error]` is a severity level, not a threadname or debug category. The log parser was treating these as threadnames, causing lines to be parsed as UnknownLogMessage instead of their correct event type (e.g. BlockCheckedLog). Add is_log_level() filter to strip known log levels (error, warning, info, debug, trace) from metadata items before category/threadname extraction. Also move block_checked.state assertions into if-let predicate guards in integration tests (same pattern as PR peer-observer#354) so that events with non-matching state are skipped rather than causing panics from event ordering races. Closes peer-observer#366
deadmanoz
added a commit
to deadmanoz/peer-observer
that referenced
this pull request
Feb 24, 2026
Bitcoin Core's LogError()/LogWarning() emit lines like `[error] AcceptBlock: ...` where `[error]` is a severity level, not a threadname or debug category. The log parser was treating these as threadnames, causing lines to be parsed as UnknownLogMessage instead of their correct event type (e.g. BlockCheckedLog). Add is_log_level() filter to strip known log levels (error, warning, info, debug, trace) from metadata items before category/threadname extraction. Also move block_checked.state assertions into if-let predicate guards in integration tests (same pattern as PR peer-observer#354) so that events with non-matching state are skipped rather than causing panics from event ordering races. Somewhat addresses peer-observer#366.. there are sill issues related to intermittent failure of some log lines making it through the `tail -f > pipe` mechanism...
deadmanoz
added a commit
to deadmanoz/peer-observer
that referenced
this pull request
Feb 25, 2026
Bitcoin Core's LogError()/LogWarning() emit lines like `[error] AcceptBlock: ...` where `[error]` is a severity level, not a threadname or debug category. The log parser was treating these as threadnames, causing lines to be parsed as UnknownLogMessage instead of their correct event type (e.g. BlockCheckedLog). Add is_log_level() filter to strip known log levels (error, warning, info, debug, trace) from metadata items before category/threadname extraction. Also move block_checked.state assertions into if-let predicate guards in integration tests (same pattern as PR peer-observer#354) so that events with non-matching state are skipped rather than causing panics from event ordering races. Somewhat addresses peer-observer#366.. there are sill issues related to intermittent failure of some log lines making it through the `tail -f > pipe` mechanism...
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.
Summary
LogDebugCategory::Netassertions from insidecheck_eventclosures intoif letguards so tests filter for the expected category rather than asserting on the firstUnknownLogMessagereceivedsetup_node,setup_two_connected_nodes, andchecktest harness functionsFixes #338
Context
On slower CPUs (e.g. my trusty old Xeon E5-2630 v4 or even GitHub's own runners), bitcoind takes longer to initialise. This caused an event ordering race.
Three tests (
unknown_with_category,unknown_with_threadname_and_category,unknown_with_all_metadata) matched the firstUnknownLogMessageand assertedcategory == Net. On slower hardware, non-net messages (e.g.dnsseed thread startwith categoryUnknown) arrive before any[net]line, causing assertion failures. Moving the category check into theif letguard lets the event loop skip non-matching messages and continue scanning until aNetcategory event arrives. If the log extractor breaks its category parsing, no event will ever match and the test will time out (preserves the original intent).Here's a snippet from from logs identifying the failure of the reported issue (#338). Note that the test expects category
Net, but the firstUnknownLogMessageis from thednsseedthread with categoryUnknown!Testing
I have run these changes through CI on my fork, all green: https://github.com/deadmanoz/peer-observer/actions/runs/21893170475