Unify time mocking strategy across the codebase
I maintainer di solito rispondono entro 4 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Refactoring
- Chiarezza
- Da chiarire
- Stato di attività
- Tranquilla
- Stack tecnologico
- rust
- Ambito
- distributed-systems, testing
Direzione di ricerca
Inizia leggendo crates/core/src/deadline.rs, crates/app/src/retry.rs, crates/core/src/qbft/fake_clock.rs e gli altri file interessati elencati nell'issue, quindi esamina le PR #18 e #276. Mappa i pattern esistenti di clock e injection, valuta le alternative proposte e definisci il completamento come una strategia temporale coerente e verificabile tra i moduli interessati, senza l'attuale flakiness temporale.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Context
Time mocking has been flagged as a recurring pain point across multiple PRs:
- PR #18 (QBFT): Tests were flaky due to reliance on real wall-clock time.
cargo nextestwas introduced specifically for timeout/retry control. A customFakeClockwas built for QBFT to work around the problem. Several tests remain#[ignore]d with timing-related failures ("wrong decide round", "wrong prepared value"). - PR #276 (Deadliner):
Utc::now()is called directly throughoutdeadline.rs, making the module untestable withtokio::time::pause()/advance(). Tests rely on real wall-clock time with short millisecond sleeps — fragile under CI load. The PR was merged with the agreement to revisit this as a separate issue.
Current state
The codebase has three unrelated time approaches coexisting:
| Approach | Where | Mockable? |
|---|---|---|
chrono::Utc::now() / chrono::Local::now() |
deadline.rs, retry.rs, peerinfo, cluster/definition.rs, p2p/k1.rs |
No (not controlled by tokio test-util) |
std::time::Instant / tokio::time::Instant |
peerinfo/protocol.rs, p2p/relay.rs, QBFT tests |
Partially (tokio variant responds to pause()/advance()) |
FakeClock (custom, crossbeam-based) |
core/qbft/fake_clock.rs |
Yes, but ad-hoc and only for QBFT |
Additionally, some modules use injectable time functions as a workaround:
retry.rshaswith_time()accepting aFn() -> DateTime<Utc>providerdeadline.rshasDeadlineFuncfor injectable deadline calculation
These are local solutions — there is no unified abstraction.
Problem
chrono::Utc::now()is invisible to tokio's test-util.tokio::time::pause()only controlstokio::time::Instantandtokio::time::sleep(). Any code usingchrono::Utc::now()will see real wall-clock time in tests, leading to flaky or non-deterministic behavior.FakeClockis QBFT-specific. It usescrossbeam::channelandstd::time::Instant— a completely different mechanism from tokio's async timers. It can't be reused for async code that usestokio::select!.- No consistent pattern for new code to follow. Each module has invented its own approach.
Proposed direction
Explore a unified time abstraction, potentially:
- Option A: Lean into
tokio::timethroughout. Replacechrono::Utc::now()withtokio::time::Instant-based calculations where possible. Usetokio::time::pause()/advance()in tests. Keepchronoonly for formatting/parsing, not as a clock source. - Option B: Create a small
Clocktrait (or crate-level abstraction as suggested in #276) that wraps the time source. Production uses real time; tests inject a controllable clock. This is more flexible but adds a layer of indirection. - Option C: Hybrid — use tokio's built-in mocking for async timer code, and a simple injectable
Fn() -> DateTime<Utc>for code that needs wall-clock timestamps.
Affected areas
Key files using chrono::Utc::now() or direct time that would benefit from unification:
crates/core/src/deadline.rscrates/app/src/retry.rscrates/peerinfo/src/protocol.rs,config.rs,behaviour.rscrates/cluster/src/definition.rscrates/p2p/src/k1.rscrates/core/src/qbft/fake_clock.rs(custom mock)crates/app/src/privkeylock.rs
References
- #18 — QBFT implementation (flaky tests,
FakeClockintroduction) - #276 — Deadliner (time mocking discussion)
- tokio test-util docs
- Lingua principale
- Rust
- Stelle
- 8
- Fork
- 6
- Merge medio
- 4g 3h
- PR unite (30g)
- 18
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di NethermindEth/pluto
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
NethermindEth/pluto#719 ·
I maintainer di solito rispondono entro 4 giorni
-
enhancement rust
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
NethermindEth/pluto#640 ·
I maintainer di solito rispondono entro 4 giorni
-
rust
Difficoltà 5/5 Più di una settimana Idoneità per principianti 45/100
NethermindEth/pluto#638 · 1 commento ·
I maintainer di solito rispondono entro 4 giorni
-
enhancement rust
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
NethermindEth/pluto#635 ·
I maintainer di solito rispondono entro 4 giorni
-
Improve `alpha test peers`: match Charon's probes; reduce timeoutsForse già presa @varex83agent l’ha presa 6 giorni fa. Apertabug track:orchestration-cli
Difficoltà 5/5 Più di una settimana Idoneità per principianti 28/100
NethermindEth/pluto#632 ·
I maintainer di solito rispondono entro 4 giorni
Tutte le issue di NethermindEth/pluto
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
bmander/geomsolver#118 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Three Windows builds are keyed on a later release than their layoutForse già presa @ero-qt l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 2 giorni
-
priority:P3 type:docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
sebastian-software/ferroni#253 ·
I maintainer di solito rispondono entro 1 giorno