Tests: two persistence gaps (how a stopping or snapshotting effect settles, a store timeout of `Duration::MAX`)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
The proposed tests and command variant belong in tests/persistence.rs, beside StopAfter and the tests named in the issue. Read those tests and the referenced guarantees in docs/persistence.md and the Rust docs to understand the expected behavior. Add the three regression tests and command variant described, then run the feature-enabled test command from the issue; done means all three catch their mutations and the cluster tests still pass.
Written by the indexing model from the issue text.
Description
Two guarantees of persistence have no test on 392a3bf. In each, the code does what the docs say, and no test would notice if it stopped. Each item quotes the guarantee and names the mutations which pass the cargo test -p tellus run of just test with --features persistence-tests,persistence-in-memory,cluster-dev,serde,test-util,__internal. The run without features does not build persistence. The tests, in tests/persistence.rs, fail under them and pass 10 of 10 runs on 392a3bf. With the tests in place, each of the four mutations fails exactly one test, and tests/cluster.rs still passes. A test runs alone like cargo test -p tellus --features persistence-in-memory --test persistence a_stopping_effect_settles_before_the_actor_stops.
1. How a stopping or snapshotting effect settles
Three statements. The rustdoc of Effect::and_stop (effect.rs 54 to 55): "Stop this actor once this effect is settled, i.e. after its events are durable and applied and its then continuations have run." docs/persistence.md 153 to 154, with no exception for an effect which stops: "Fully settled means that its events are durable and applied, its then has run and the save of a due snapshot has been attempted." And 53 to 54: "snapshot optionally offers a snapshot after an effect with events, once its events have been applied and its continuations have run."
Three mutations of settle_or_log_failure (persistence/spawn.rs 740 to 766) each pass every test. With for then in thens.into_iter().filter(|_| !stop) at 741, a stopping effect runs no continuation, so a reply from the then of Effect::persist(..).and_stop() never comes, and the asker gets NoReply. With if appended && !stop at 750, a stopping effect saves no snapshot, so the next recovery replays more. With the snapshot block (750 to 766) moved in front of the continuations (740 to 748), a continuation waits for the save, a hanging one up to the store timeout.
The first test catches the first two mutations. It needs a variant of Command beside StopAfter(u64):
StopAfterAndGet(u64, ReplyTo<u64>),
handled in counter_effect beside Command::StopAfter(n):
Command::StopAfterAndGet(n, reply_to) => Ok(Effect::persist(Increased(n))
.and_stop()
.then(move |count| reply_to.reply(*count))),
The second test catches the third mutation. Both go after a_command_settles_before_the_next_is_handled:
/// A stopping effect is fully settled before the actor stops: its continuation runs, and its due
/// snapshot is saved.
#[tokio::test]
async fn a_stopping_effect_settles_before_the_actor_stops() {
let store = FaultyStore::default();
let (probe_tx, _probe_rx) = mpsc::unbounded_channel();
let system = ActorSystem::event_sourced(
Counter::new("stopping", probe_tx).with_snapshot_every(1),
Persistence::new(store.clone()).with_snapshot_store(store.clone()),
);
let count = system
.root()
.ask(TIMEOUT, |reply_to| Command::StopAfterAndGet(3, reply_to))
.await
.expect("the continuation of the stopping effect must run");
assert_eq!(count, 3);
assert_terminates(system, "system did not terminate").await;
assert_eq!(
store
.inner()
.snapshot(&persistence_id("stopping"))
.map(|stored| stored.next_seq_no),
Some(SeqNo::new(1)),
"the stopping effect must save its due snapshot"
);
}
/// The continuations of an effect run before its due snapshot is saved, so a hanging save does not
/// delay them.
#[tokio::test(start_paused = true)]
async fn continuations_run_before_a_due_snapshot_is_saved() {
let store = FaultyStore::default().with_hanging_saves(1);
let (probe_tx, mut probe_rx) = mpsc::unbounded_channel();
let system = ActorSystem::event_sourced(
Counter::new("then-before-snapshot", probe_tx).with_snapshot_every(1),
bounded(&store).with_snapshot_store(store.clone()),
);
assert_eq!(recv(&mut probe_rx, "no init probe").await, Probe::Init);
assert_eq!(
recv(&mut probe_rx, "no recovered probe").await,
Probe::Recovered
);
let told_at = Instant::now();
system.root().tell(Command::Increment(1));
assert_eq!(
recv(&mut probe_rx, "no handled probe").await,
Probe::Handled
);
assert_eq!(
recv(&mut probe_rx, "no settled probe").await,
Probe::Settled(1)
);
let elapsed = told_at.elapsed();
assert!(
elapsed < STORE_TIMEOUT,
"the continuation must run before the hanging save, it ran after {elapsed:?}"
);
system.root().tell(Command::Stop);
assert_terminates(system, "system did not terminate").await;
}
With the continuations skipped, with the snapshot skipped, and with the snapshot block in front of the continuations (panic messages only):
thread 'a_stopping_effect_settles_before_the_actor_stops' (18949758) panicked at tellus/tests/persistence.rs:1284:10:
the continuation of the stopping effect must run: NoReply
thread 'a_stopping_effect_settles_before_the_actor_stops' (18907098) panicked at tellus/tests/persistence.rs:1288:5:
assertion `left == right` failed: the stopping effect must save its due snapshot
left: None
right: Some(SeqNo(1))
thread 'continuations_run_before_a_due_snapshot_is_saved' (19001601) panicked at tellus/tests/persistence.rs:1326:5:
the continuation must run before the hanging save, it ran after 1s
The second test pins what a user sees, a continuation not held behind a hanging save. It does not pin when snapshot itself is called: with snapshot called before the continuations and its result saved after them, every test passes, this one included. A continuation gets the state by shared reference only. So snapshot sees the same state either way, unless the state has interior mutability.
2. A store timeout of Duration::MAX is capped
docs/persistence.md 192 to 193: "A timeout the clock cannot represent from the start of a store call, e.g. Duration::MAX, is capped there at about 30 years." The rustdoc of Persistence::with_timeout (persistence.rs 82 to 84) says the same.
Every store call goes through within. With timeout_at(Instant::now() + timeout, call) in place of timeout_at(timers::deadline(Instant::now(), timeout), call) there (persistence/spawn.rs 944), every test passes. A Persistence with with_timeout(Duration::MAX) then fails every recovery at its first store call. A timer's delay (timers.rs 770) and the cluster's durations (#337) have tests with Duration::MAX; the store timeout has none.
The test, in tests/persistence.rs after a_hung_snapshot_save_never_fails_the_actor:
/// A store timeout the clock cannot represent, `Duration::MAX`, is capped: recovery, an append and
/// a snapshot save all complete under it.
#[tokio::test]
async fn a_store_timeout_of_duration_max_is_capped() {
let store = FaultyStore::default();
let (probe_tx, _probe_rx) = mpsc::unbounded_channel();
let system = ActorSystem::event_sourced(
Counter::new("timeout-max", probe_tx).with_snapshot_every(1),
Persistence::new(store.clone())
.with_snapshot_store(store.clone())
.with_timeout(Duration::MAX)
.expect("the store timeout is not zero"),
);
system.root().tell(Command::Increment(1));
assert_eq!(ask_count(&system).await, 1);
assert_eq!(
store
.inner()
.snapshot(&persistence_id("timeout-max"))
.map(|stored| stored.next_seq_no),
Some(SeqNo::new(1)),
"the snapshot save must complete"
);
system.root().tell(Command::Stop);
assert_terminates(system, "system did not terminate").await;
}
Under the mutation, in the second run of just test (run alone, the test prints the two panics only), with the registry path shortened:
thread 'a_store_timeout_of_duration_max_is_capped' (19036189) panicked at .../tokio-1.54.1/src/time/instant.rs:161:27:
overflow when adding duration to instant
2026-12-01T12:46:40.192415Z ERROR tellus::actor_context: actor failed to recover actor_id=01a231a4-9840-759e-9938-7193ea51629e panic=overflow when adding duration to instant
thread 'a_store_timeout_of_duration_max_is_capped' (19036189) panicked at tellus/tests/persistence.rs:2370:10:
no reply to get: NoReply
Suggestion: add the three tests and the variant, each where it is named above. Nothing in the code needs to change.
- Dominant language
- Rust
- Stars
- 37
- Forks
- 1
- Avg merge
- 4h 56m
- Merged PRs (30d)
- 219
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tellus-rs/tellus
-
bug
Difficulty 1/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
documentation
Difficulty 1/5 Under an hour Newbie friendliness 91/100
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
All issues in tellus-rs/tellus
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
aaif-goose/goose#13970 ·
Maintainers usually reply within 1 day
-
comp-documentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ClickHouse/ClickHouse#136277 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Copperpour/Copperpour#1105 ·
Maintainers usually reply within 1 day
-
bug release-blocker
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day