cultcache-rs: pin the default clock, collapse the stamp gate, name the random-id limit in the README
All checks were successful
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Successful in 32m33s
All checks were successful
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Successful in 32m33s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
bb88387227
commit
c30970479c
2 changed files with 21 additions and 5 deletions
|
|
@ -170,7 +170,7 @@ without pretending Rust has runtime reflection hiding under the floorboards.
|
|||
## Current Surface
|
||||
|
||||
- `CultCache::new`
|
||||
- `set_clock` (the clock that stamps fresh writes; pin it for reproducible stores)
|
||||
- `set_clock` (the clock that stamps fresh writes; pin it for reproducible stores; a writer that mints random values of its own, such as the C# writer's unset element ids, still breaks byte-identity)
|
||||
- `register_entry_type::<T>`
|
||||
- `add_generic_backing_store`
|
||||
- `add_backing_store`
|
||||
|
|
|
|||
|
|
@ -4754,10 +4754,12 @@ fn successor_stamp(replaced: &str) -> Result<Option<String>> {
|
|||
/// is strictly later than `replaced`; otherwise the replaced stamp plus one microsecond. A `replaced` that does not parse
|
||||
/// leaves nothing to be later than, so `staged` stands.
|
||||
fn stored_at_over(staged: &str, replaced: &str) -> Result<String> {
|
||||
if let (Ok(staged_at), Ok(replaced_at)) = (chrono::DateTime::parse_from_rfc3339(staged), chrono::DateTime::parse_from_rfc3339(replaced)) {
|
||||
if staged_at > replaced_at {
|
||||
return Ok(staged.to_string());
|
||||
}
|
||||
let later = matches!(
|
||||
(chrono::DateTime::parse_from_rfc3339(staged), chrono::DateTime::parse_from_rfc3339(replaced)),
|
||||
(Ok(staged_at), Ok(replaced_at)) if staged_at > replaced_at
|
||||
);
|
||||
if later {
|
||||
return Ok(staged.to_string());
|
||||
}
|
||||
Ok(successor_stamp(replaced)?.unwrap_or_else(|| staged.to_string()))
|
||||
}
|
||||
|
|
@ -5907,6 +5909,20 @@ mod tests {
|
|||
Ok(cache)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_cache_with_no_set_clock_stamps_near_now() -> Result<()> {
|
||||
let temp = tempfile::tempdir()?;
|
||||
let mut cache = CultCache::new();
|
||||
cache.register_entry_type::<Settings>()?;
|
||||
cache.add_generic_backing_store(SingleFileMessagePackBackingStore::new(temp.path().join("a.cc")))?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
cache.put("app", &settings_one())?;
|
||||
let stamp = cache.get_required_envelope::<Settings>("app")?.stored_at;
|
||||
let stamped = chrono::DateTime::parse_from_rfc3339(&stamp).unwrap().with_timezone(&chrono::Utc);
|
||||
assert!((chrono::Utc::now() - stamped).num_seconds().abs() < 5, "{stamp}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn two_replays_with_a_pinned_clock_write_identical_bytes() -> Result<()> {
|
||||
let temp = tempfile::tempdir()?;
|
||||
|
|
|
|||
Loading…
Reference in a new issue