Skip to content

Test that the background received-certificate sync actually repeats - #6837

Merged
ndr-ds merged 1 commit into
linera-io:mainfrom
ndr-ds:ndr-ds/test-periodic-sync-repeats
Sep 18, 2026
Merged

ndr-ds merged 1 commit into
linera-io:mainfrom
ndr-ds:ndr-ds/test-periodic-sync-repeats

Conversation

@ndr-ds

@ndr-ds ndr-ds commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Motivation

#6830 made the background received-certificate sync repeat on an interval, because that sync is the only thing that advances the per-validator trackers — without it, every process restart walks the entire backlog accumulated since the previous restart (3.8M log entries on one live chain, saturating validator storage for the length of the walk).

Nothing tests the part that matters. Every listener test in the file constructs ChainListener::new(..., false) — background sync disabled — so the loop never runs at all, let alone twice. And the tests that do build a config use ChainListenerConfig::default(), which since #6830 means a 15-minute interval, so even if one enabled the sync it would only ever observe the first pass.

The behaviour change is therefore entirely unexercised: reviewed by reading, never run.

Proposal

background_sync_repeats starts a listener with background sync enabled and a 50 ms interval, and asserts the sync keeps running.

Counting is done by incrementing a counter in the test context's timing_sender(). In this crate the only caller of timing_sender is the default make_chain_client (chain_listener.rs:157; the other call site is the production ClientContext, not this test double), and the sync makes exactly one chain client per pass — so the counter counts passes without duplicating any production logic in the test double. If that coupling ever breaks the counter stops rising and the test fails; it cannot silently pass.

Test Plan

$ cargo test -p linera-client --lib chain_listener
test result: ok. 8 passed; 0 failed

The assertion is on growth, not on a total, and that distinction was found the hard way. The first version asserted >= 3 chain clients and passed in 0.05 s — including with background_sync_interval_ms: 0, i.e. the pre-#6830 one-shot behaviour. Startup makes exactly 3 chain clients on its own, so any fixed threshold is met without the loop ever repeating: a tautology.

The test now lets startup settle, records that baseline, and requires the count to climb by 2 more. Verified by mutation:

# with background_sync_interval_ms: 0  (pre-fix behaviour)
test unit_tests::chain_listener::background_sync_repeats ... FAILED
Error: background sync did not repeat: 3 chain clients made, still at the 3 from startup

# with background_sync_interval_ms: 50
test unit_tests::chain_listener::background_sync_repeats ... ok

Release Plan

  • These changes should be backported to the latest testnet branch.

Test-only, no production change. Worth backporting so the conway branch has the same guard.

Links

@ndr-ds
ndr-ds marked this pull request as ready for review September 18, 2026 01:33
@ndr-ds
ndr-ds merged commit 672d97b into linera-io:main Sep 18, 2026
43 checks passed
@ndr-ds
ndr-ds deleted the ndr-ds/test-periodic-sync-repeats branch September 18, 2026 01:33
ndr-ds added a commit that referenced this pull request Sep 18, 2026
…repeats (#6838)

Backport of #6837 to `testnet_conway`.

## Motivation

#6835 (the conway backport of #6830) made the background
received-certificate sync repeat on an interval, because that sync is
the only thing that advances the per-validator trackers. It shipped to
the PM workers in `linera-client @ 4b46d92` with nothing on this branch
testing the part that matters: every other listener test here constructs
`ChainListener::new(..., false)`, so the loop never runs at all, let
alone twice.

## Proposal

`background_sync_repeats` starts a listener with background sync
**enabled** and a 50 ms interval, and asserts the sync keeps running.
Counting is done by incrementing a counter in the test context's
`timing_sender()` — in this crate its only caller is the default
`make_chain_client`, and the sync makes exactly one chain client per
pass.

Two deltas from the `main` version, both mechanical:

- conway's `Client::new` takes `requests_scheduler_config` **before**
the two cache sizes; `main` takes it last. The cherry-pick carried
`main`'s order and did not compile.
- conway has no `test_chain_listener_untracks_after_unsubscribe` (#4260
was never backported), so the hunk adding `chain_clients_made` to that
test's context was dropped.

## Test Plan

```
$ cargo test --locked -p linera-client --lib chain_listener
test result: ok. 7 passed; 0 failed
```

Verified by mutation on this branch, not just inherited from `main`:

```
# background_sync_interval_ms: 0  (pre-#6835 one-shot behaviour)
test unit_tests::chain_listener::background_sync_repeats ... FAILED
Error: background sync did not repeat: 3 chain clients made, still at the 3 from startup

# background_sync_interval_ms: 50
test unit_tests::chain_listener::background_sync_repeats ... ok
```

`cargo clippy -p linera-client --all-targets --all-features` clean;
`cargo +nightly-2025-06-10 fmt --all -- --check` clean.

## Release Plan

- Nothing to do / backport of an already-released change.

Test-only, no production change.

## Links

- [reviewer
checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
- Backport of #6837; covers #6835.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.

1 participant