Unify time mocking strategy across the codebase
Los mantenedores suelen responder en 4 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Refactorización
- Claridad
- Necesita aclaración
- Estado de actividad
- Tranquilo
- Stack tecnológico
- rust
- Área
- distributed-systems, testing
Línea de trabajo
Empieza leyendo crates/core/src/deadline.rs, crates/app/src/retry.rs, crates/core/src/qbft/fake_clock.rs y los demás archivos afectados indicados en el issue; después, revisa los PRs #18 y #276. Mapea los patrones existentes de clock e inyección, evalúa las alternativas propuestas y define la finalización como una estrategia temporal coherente y comprobable en los módulos afectados, sin la inestabilidad temporal actual.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Rust
- Estrellas
- 8
- Forks
- 6
- Merge medio
- 4 d 3 h
- PR fusionados (30 d)
- 18
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de NethermindEth/pluto
-
Dificultad 4/5 3-5 días Aptitud para principiantes 52/100
NethermindEth/pluto#719 ·
Los mantenedores suelen responder en 4 días
-
enhancement rust
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
NethermindEth/pluto#640 ·
Los mantenedores suelen responder en 4 días
-
rust
Dificultad 5/5 Más de una semana Aptitud para principiantes 45/100
NethermindEth/pluto#638 · 1 comentario ·
Los mantenedores suelen responder en 4 días
-
enhancement rust
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
NethermindEth/pluto#635 ·
Los mantenedores suelen responder en 4 días
-
Improve `alpha test peers`: match Charon's probes; reduce timeoutsPosiblemente ocupada @varex83agent la tomó hace 7 días. Abiertobug track:orchestration-cli
Dificultad 5/5 Más de una semana Aptitud para principiantes 28/100
NethermindEth/pluto#632 ·
Los mantenedores suelen responder en 4 días
Todos los issues de NethermindEth/pluto
Issues similares
-
documentation enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
adorsys/status-list-server#619 ·
Los mantenedores suelen responder en 2 días
-
batch-backport only backports the first 30 matching PRsPosiblemente ocupada @DvirDukhan la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 5 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
equinor/septic-config-generator#481 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día