← Back to Pull requests

test(gossip): pilot for component tests #1744

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Jul 21, 2026 00:22 UTC
Author

Summary

Goal of this PR is to establish some patterns for component tests (using gossip as a testing pilot target).
Additionally I have added a writeup to this PR description to start organizing ideas and patterns for testing and observability, I think it can evolve into a testing.md type of document. The goal of this writeup is to record ideas and solutions for testing and observability that are not immediately obvious or apparent from the code, and to help establish a style and pattern of testing.

Main Changes for Tests

  • Added deterministic in-process gossip component tests covering some scenarios (not exhaustive).

  • Added raw-packet and stateful gossip fuzz tests that validate emitted packets and internal invariants (proof of concept).

  • Added TestNode, an in-process GossipNode harness with deterministic identity, simulated time, captured outgoing packets, captured snapshot sources, reset support, and invariant checks.

  • Added TestMetricStore for allocator-backed metric registration and reset without exposing or running a complete telemetry region. This allows for reading and asserting metric values.

  • Added reusable lib.gossip.testing helpers for deterministic keypairs, signed gossip values, message encoding, and decoding. These are shared by component, fuzz, and black-box tests.

  • Added configurable GossipNode capacity limits so component tests can use smaller fixed-buffer allocations.

  • Integrated component and fuzz tests into the standard unit-test step and documented unit, black-box, filtered, and fuzz test commands in README.md.
  • Adjacent Changes

  • Fix crash when receiving deprecated gossip message and add test to cover the scenario.

  • Deleted the obsolete gossip/bincode.zig; gossip now uses v2/lib/solana/bincode.zig.

  • Renamed raw u64 time parameters and local values with an _ms suffix. Serialized gossip protocol fields retain their protocol-defined names.

  • Added test-facing gossip state inspection and invariant helpers.

  • Consolidated table key and value metadata extraction into EntryInfo.fromData().

  • Added Variant.get() for metric assertions.

  • Updated telemetry metric-capacity documentation to clarify storage requirements.
  • Known Future TODO

  • Gossip tests are just initial tests for example of approach and organization, these initial tests are not a full suite of coverage.

  • Logger handling in tests not done, there is some additional improvements/fixes to logging so it will be in follow up PR.

  • Alerts mentioned in writeup but also not done (part of logging changes).
  • Testing Writeup

    Categories of Tests

    Unit Tests

  • Unit tests should be the first kind of test considered for any new code.

  • Colocated with production source.

  • Execution is deterministic.

  • Best for behavior that can be isolated to single functions with clear input -> output, e.g., serialize/deserialize, algorithmic building blocks, core data structures, anything without long lived running state.
  • Component Tests

  • These tests make use the Zig unit test tooling but are focused on sequences and scenarios with longer lived state, and may have extensive helper code and harnesses to track and assert invariants.

  • Component code must be deeply testable! Fortunately Zig makes this often easy to do without incuring any performance cost in production.

  • Single threaded and deterministic.

  • Component invariants are asserted broadly and repeatedly as state is changed under test.

  • Tests, asserts, and associated harnesses should consider coverage from two perspectives:

  • - Externally how is the component utilized and interacted with: inputs -> outputs and expected behavior.
    - Internally what are the control flow paths and invariants of internal state.
  • Sequences of operations should have small comments describing the intent for blocks of code (interactions and asserts) for each "phase" in the sequence, making it easy for the reader to understand the intent and verify the code does what is intended.

  • Not a replacement for unit tests even if there is overlap, unit tests should always be the first approach where possible.

  • Multi-component tests are also possible if helpful for simulating interactions, they can utilize helper/harness code for both components.

  • Helper and test harness code may also be utilized in fuzzing tests.
  • Blackbox (Service) Tests

  • Real service processes (main entry) using shared-memory regions.

  • Does not verify internal state but verifies external state and that services work together through shared-memory.

  • Useful as a general "smoke test" that things work (without running the complete validator), and for more complex shared-memory interactions.

  • Should strive to be repeatable but may not be completely deterministic due to multi-process/threading and possible IO.
  • System Tests

  • May use code under test as library or run as parallel process, may even run the entire validator with some setup and scenario.

  • Has dedicated tooling (ledger tests, network tests, etc.) beyond just helpers and harnesses within the Zig testing api.

  • These tests include things like external runtime conformance fixtures and tests.

  • Similar to blackbox tests should strive to be repeatable but may not be deterministic.
  • Fuzzing

  • Fuzzing is mostly focused around component and system tests.

  • Component tests can make use of Zig std fuzzing api to define fuzzing tests that can be run through the zig cli.

  • External fuzzing tools may run as system tests and not utilize Zig's std fuzzing.
  • Asserts and Alerts

    Asserts

  • Asserts for invariants in tests should be done with actual asserts rather than returning a Boolean or a struct with information, this ensures simple 1:1 mapping when an invariant fails (fast to debug as the source of failure is obvious) and avoids adding boilerplate and other indirection.

  • Assert everything that is acceptable to check in production code (considering runtime performance when building with release safe) that is unrecoverable.

  • Some invariant asserts for tests may involve more work like looping over all items in a data structure to check properties maintain some consistency, but this may be too expensive to do in production code. In such cases, this inspection would be part of test asserts (maybe exposed by a function), but not in production code.
  • Logged Alerts

    Logged alerts are labeled logs that are easy to match in observability tools to trigger an alert. A labeled alert allows for the developer on the code side of things reason about producing an event that should be noisy to observers.

    The value of an alert based on a labeled log is they can be reasoned about and maintained solely in the code, and they are single point events with unique messages/payload. This is in contrast to metrics based alerts which are created by queries on counts, gauges, histograms, etc. These queries are outside of the code and operate on aggregations.

    Logged alerts do not replace asserts or metric query based alerts in grafana (or other tools). Logged alerts should only be considered when an assert or metric alert is inadequate or unwieldy. Examples:

  • An unusual amount of time was taken for some step in the code, a logged alert can provide the exact time taken rather than just seeing a count in a histogram that it was above the largest bucket defined.

  • State was detected at a particular point in the control flow that should never happen (according to the engineer), a logged alert can uniquely identify this event back to the code without crashing the process.
  • Initial thinking is there are two kinds of alerts, categorized by audience: dev and operator.

    An operator alert is something a node operator would want to be informed of. It would indicate something an operator has control of, for example disk space, network access, etc.

    A dev alert indicates an unexpected control flow or state was detected, but the code may handle the circumstance gracefully (should not crash the process).

  • All unexpected state and control flow should have a dev alert even if the code handles it gracefully to ensure it is reviewed, the code is correct, and documented (the alert should either be removed with comment for how it's possible and handled properly, or if it's a bug then the bug should be fixed). This is much better than a silent continuation (especially given it could indicate a bug).

  • operator alerts are useful for things that may be caused by the environment the node is running in.

  • Things that are known to have transient failures should not immediately produce an operator alert on first failure. E.g., it's expected that network IO can fail intermittently, only after some threshold should an alert be produced (for this case it's likely a metric query is more adequate).

  • dev alerts should always cause tests to fail, they indicate unexpected control flow or state and even if harmless indicate a bug according to reasoning.

  • operator alerts should cause tests to fail unless the alert path is being tested.

  • Logged alerts are not exhaustive to all things, and need not be complete failures, for example if it takes 30 seconds to read a file but the read succeeds that should alert as a warning to the operator. Most operator alerts will be better organized as metric queries (e.g., repeated failures in networking, or sustained high disk IO latency).
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: ajw221 Review duration: 195842m
    All Vouch review confidence checks passed
    Residual risk 0.35 = Change Risk (0.59) × (1 − Review Confidence (0.41)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.59 · 650 lines diff across 8 files
    0.59
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    40%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #1744"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 40.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 59% (MEDIUM) · Higher = larger blast radius
    59%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 40.9% · Lower = rushed or shallow review
    40.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 34.8% · Safe to merge
    34.8%
    Repository