Skip to content

test(node): isolate sync lag observations - #662

Merged
beardthelion merged 1 commit into
mainfrom
tests/sync-lag-flake
Dec 2, 2026
Merged

beardthelion merged 1 commit into
mainfrom
tests/sync-lag-flake

Conversation

@beardthelion

@beardthelion beardthelion commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The sync lag tests now check their own observations. The sync worker still records to the same Prometheus histogram under the same conditions.

Motivation & context

In the failed CI run on #651, the failed-tip test expected the histogram count to stay at 1 but read 2. Both tests use the same process-wide histogram, so a sample from another test can land between those reads.

Kind of change

  • Bug fix
  • Feature
  • Security fix
  • Docs
  • Tests / CI
  • Refactor (no behavior change)
  • Breaking or protocol change (issue required first)

What changed

  • twigpine-node: pass the sample recorder into the lag gate. The worker passes the existing metric recorder, and the tests use callbacks that don't touch the shared histogram.
  • Keep the existing checks for a matching tip, confirmed deletion, a failed read, a mismatched tip, and a quarantined mirror.

How a reviewer can verify

Set DATABASE_URL to a local PostgreSQL 16 database, then run:

cargo fmt --all --check
for run in 1 2 3; do
  cargo test --locked --workspace || exit 1
done
cargo clippy --locked --workspace --all-targets -- -D warnings

Formatting passed. On PostgreSQL 16.16, each workspace run had 3,836 passed, 0 failed, and 20 ignored. Both lag-gate tests passed in every run.

Before you request review

  • Scope is one logical change; no unrelated churn
  • cargo test --workspace passes locally
  • New behavior is covered by tests (required for fixes)
  • cargo fmt --all and cargo clippy --workspace --all-targets -- -D warnings are clean
  • Commit titles use Conventional Commits (feat(...), fix(...), docs(...))
  • Docs / .env.example updated if behavior or config changed (or N/A)
  • Checked existing PRs so this isn't a duplicate

Notes for reviewers

Strict local Clippy reported double_must_use in the unchanged BlockStore trait. With only that lint allowed, Clippy passed:

cargo clippy --locked --workspace --all-targets -- -D warnings -A clippy::double_must_use

Summary by CodeRabbit

  • Tests
    • Expanded validation of sync-lag reporting across successful and unsuccessful synchronization scenarios, including cases where mirrors are quarantined.
    • Confirmed that observations are recorded only when synchronization results meet the existing visibility checks.
  • Refactor
    • No user-facing behavior changed; adjustments were limited to testability and test comments.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The sync-lag visibility gate now accepts an observation callback and invokes it only after its existing checks pass. Production passes the metrics observer. Tests use a local counter to verify when the callback runs.

Changes: Sync-Lag Observation

Layer / File(s) Summary
Observer injection and visibility tests
crates/twigpine-node/src/sync.rs, crates/twigpine-node/src/metrics.rs
The visibility gate accepts and invokes a callback, and production passes the metrics observer. Tests use a local counter to check which outcomes produce observations. The test-only histogram helper is removed, and related comments are shortened.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Suggested labels: crate:node

Suggested reviewers: kevincodex1

Merge Risk: Minimal · up to 827cb

This change makes the sync-lag tests independent of shared process-wide metrics, which removes a flaky test failure. Production lag recording behaves as before, so the merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "test(node): isolate sync lag observations" matches the main change. The sync lag tests now record observations through their own callbacks instead of the shared process-wide Prometheus hist…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description states the purpose (tests check their own sync lag observations, worker unchanged), motivation with a linked failed CI run on #651, the kind of change, a list of what changed, and veri…
Full details: Title check

Explanation

The title "test(node): isolate sync lag observations" matches the main change. The sync lag tests now record observations through their own callbacks instead of the shared process-wide Prometheus histogram. It follows Conventional Commits style and names the affected crate. The raw summary also shows a supporting change in sync.rs, where the observation callback is injected, which the title does not mention, but the title still covers the primary change.

Full details: Description check

Explanation

The description states the purpose (tests check their own sync lag observations, worker unchanged), motivation with a linked failed CI run on #651, the kind of change, a list of what changed, and verification steps with results. It follows the template's sections, but the Motivation section omits the 'Closes #' issue link, which is only a minor gap. Two checklist items are unchecked: 'New behavior is covered by tests' and 'cargo fmt --all and cargo clippy ... are clean', yet the Notes section explains that strict Clippy reports a lint, so the Clippy item is not fully met. The PR is a test-only change, so the 'required for fixes' test item is not decisive. Overall the description is mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4e8c7211-57b3-49d4-af7b-e3fa5de1e2eb
Commits

Reviewing files that changed from the base of the PR and between 69f7f36 and 827cbf6.

Files selected for processing: 2

  • crates/twigpine-node/src/metrics.rs
  • crates/twigpine-node/src/sync.rs

Limit details: You’ve used the included review currently available.

@jatmn jatmn left a comment

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.

🟢 Thanks for the contribution. I do not see any actionable issues from my review.

Merge readiness

  • GitHub reports the PR as mergeable with required CI green on head (fmt + clippy, test (stable), test (beta), and related checks).
  • Merge policy shows BLOCKED (approval/review gate), not a code defect.
  • Live main (617e876) is 14 commits ahead of this branch’s merge-base (cb4f277). This diff does not touch release metadata, and sync.rs / metrics.rs were not modified on main in that range — rebase is optional hygiene, not required to resolve conflicts for this change set.
  • Author checklist still has unchecked template items for “new behavior covered by tests” and strict local Clippy; CI fmt + clippy passed on the PR run, consistent with the author’s double_must_use note on unchanged BlockStore code.

@beardthelion
beardthelion added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit 65d5540 Dec 2, 2026
23 checks passed
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.

2 participants