Skip to content

fix(tests): move category assertions into guards to prevent log event ordering races - #354

Merged
0xB10C merged 2 commits into
peer-observer:masterfrom
deadmanoz:feature/improve-integration-tests
Feb 12, 2026
Merged

0xB10C merged 2 commits into
peer-observer:masterfrom
deadmanoz:feature/improve-integration-tests

Conversation

@deadmanoz

@deadmanoz deadmanoz commented Feb 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Move LogDebugCategory::Net assertions from inside check_event closures into if let guards so tests filter for the expected category rather than asserting on the first UnknownLogMessage received
  • Document setup_node, setup_two_connected_nodes, and check test harness functions

Fixes #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 first UnknownLogMessage and asserted category == Net. On slower hardware, non-net messages (e.g. dnsseed thread start with category Unknown) arrive before any [net] line, causing assertion failures. Moving the category check into the if let guard lets the event loop skip non-matching messages and continue scanning until a Net category 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 first UnknownLogMessage is from the dnsseed thread with category Unknown!

2026-02-11T02:04:28.780Z INFO  [log_extractor] Started reading lines from bitcoind log pipe at /tmp/nix-shell-319968-3831661800/.tmpocGJcs/bitcoind_pipe
2026-02-11T02:04:28.806Z TRACE [log_extractor] Read log line: 2026-02-11T02:04:27Z [dnsseed] dnsseed thread start
2026-02-11T02:04:28.806Z TRACE [shared::protobuf::event] creating new Event: LogExtractor(Log { log_timestamp: 1770775467000000, category: Unknown, threadname: "dnsseed", log_event: Some(UnknownLogMessage(UnknownLogMessage { raw_message: "dnsseed thread start" })) })
2026-02-11T02:04:28.806Z TRACE [log_extractor] published log into NATS: Event { timestamp: 1770775468806, peer_observer_event: Some(LogExtractor(Log { log_timestamp: 1770775467000000, category: Unknown, threadname: "dnsseed", log_event: Some(UnknownLogMessage(UnknownLogMessage { raw_message: "dnsseed thread start" })) })) }
2026-02-11T02:04:28.806Z TRACE [log_extractor] Read log line: 2026-02-11T02:04:27Z [dnsseed] Loading addresses from DNS seed dummySeed.invalid.

Testing

I have run these changes through CI on my fork, all green: https://github.com/deadmanoz/peer-observer/actions/runs/21893170475

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
deadmanoz force-pushed the feature/improve-integration-tests branch from bd1ad43 to 164e279 Compare February 11, 2026 06:01
/// - 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, thanks!

@0xB10C

0xB10C commented Feb 12, 2026

Copy link
Copy Markdown
Collaborator

Thank you! One step closer to no tests failing intermittently!

@0xB10C
0xB10C merged commit d9b0ff3 into peer-observer:master Feb 12, 2026
10 checks passed
@deadmanoz

Copy link
Copy Markdown
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...
@deadmanoz
deadmanoz deleted the feature/improve-integration-tests branch May 28, 2026 08:35
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.

Intermittent integration test failure of test_integration_logextractor_unknown_with_category

2 participants