diff --git a/epiphany-core/src/persona_social_state.rs b/epiphany-core/src/persona_social_state.rs index 19ca4e66..b1920e08 100644 --- a/epiphany-core/src/persona_social_state.rs +++ b/epiphany-core/src/persona_social_state.rs @@ -891,3 +891,36 @@ fn stable_pending_mention_id( fn now_iso() -> String { chrono::Utc::now().to_rfc3339() } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn persona_social_cache_reads_without_writing_the_store() -> Result<()> { + let temp = tempfile::tempdir()?; + let store = temp.path().join("social.cc"); + let cache = persona_social_cache(&store)?; + let head = PersonaSocialRetentionHeadDocument { + head: PersonaConversationRetentionHead::default(), + }; + SingleFileMessagePackBackingStore::new(&store).push( + &cache + .prepare_entry(PERSONA_SOCIAL_RETENTION_HEAD_KEY, &head)? + .0, + )?; + let past = std::time::UNIX_EPOCH + std::time::Duration::from_secs(1_000_000_000); + std::fs::File::options() + .write(true) + .open(&store)? + .set_modified(past)?; + let reopened = persona_social_cache(&store)?; + assert_eq!( + reopened + .get::(PERSONA_SOCIAL_RETENTION_HEAD_KEY)?, + Some(head) + ); + assert_eq!(std::fs::metadata(&store)?.modified()?, past); + Ok(()) + } +} diff --git a/epiphany-core/src/resident_self.rs b/epiphany-core/src/resident_self.rs index 66e66df9..21c4a46e 100644 --- a/epiphany-core/src/resident_self.rs +++ b/epiphany-core/src/resident_self.rs @@ -2730,6 +2730,31 @@ mod pressure_replay_tests { Ok(()) } + #[test] + fn state_cache_reads_without_writing_the_store() -> Result<()> { + let temp = tempfile::tempdir()?; + let store = temp.path().join("resident.cc"); + let cache = state_cache(&store)?; + SingleFileMessagePackBackingStore::new(&store).push( + &cache + .prepare_entry(RESIDENT_SELF_STATE_KEY, &ResidentSelfState::default())? + .0, + )?; + let past = std::time::UNIX_EPOCH + std::time::Duration::from_secs(1_000_000_000); + std::fs::File::options() + .write(true) + .open(&store)? + .set_modified(past)?; + let reopened = state_cache(&store)?; + assert!( + reopened + .get::(RESIDENT_SELF_STATE_KEY)? + .is_some() + ); + assert_eq!(std::fs::metadata(&store)?.modified()?, past); + Ok(()) + } + #[test] fn configured_operator_pressure_replay_preserves_the_first_document() -> Result<()> { let temp = tempfile::tempdir()?;