Skip to content

Commit

Permalink
chore(jans-cedarling): SparKV rectify expiry tests
Browse files Browse the repository at this point in the history
Signed-off-by: John Anderson <[email protected]>
  • Loading branch information
djellemah committed Jan 13, 2025
1 parent 53cbffd commit 813b716
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions jans-cedarling/sparkv/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,20 @@ fn test_clear_expired() {
_ = sparkv.set_with_ttl(
"not-yet-expired",
"v".into(),
Duration::new(0, 90).expect("a valid duration"),
Duration::new(90, 0).expect("a valid duration"),
);
_ = sparkv.set_with_ttl(
"expiring",
"value".into(),
Duration::new(1, 0).expect("a valid duration"),
// originally from_millis(1)
Duration::new(0, 1_000_000).expect("a valid duration"),
);
_ = sparkv.set_with_ttl(
"not-expired",
"value".into(),
Duration::new(60, 0).expect("a valid duration"),
);
std::thread::sleep(std::time::Duration::from_nanos(2));
std::thread::sleep(std::time::Duration::from_millis(2));
assert_eq!(sparkv.len(), 3);

let cleared_count = sparkv.clear_expired();
Expand All @@ -207,7 +208,8 @@ fn test_clear_expired_with_overwritten_key() {
_ = sparkv.set_with_ttl(
"no-longer",
"value".into(),
Duration::new(0, 1).expect("a valid duration"),
// originally from_millis(1)
Duration::new(0, 1_000_000).expect("a valid duration"),
);
_ = sparkv.set_with_ttl(
"no-longer",
Expand Down Expand Up @@ -237,7 +239,8 @@ fn test_clear_expired_with_auto_clear_expired_enabled() {
_ = sparkv.set_with_ttl(
"no-longer",
"value".into(),
Duration::new(1, 0).expect("a valid duration"),
// originally from_millis(1)
Duration::new(0, 1_000_000).expect("a valid duration"),
);
_ = sparkv.set_with_ttl(
"no-longer",
Expand All @@ -250,7 +253,7 @@ fn test_clear_expired_with_auto_clear_expired_enabled() {
"value".into(),
Duration::new(60, 0).expect("a valid duration"),
);
assert_eq!(sparkv.expiries.len(), 3); // diff from above, because of auto clear
assert_eq!(sparkv.expiries.len(), 2); // diff from above, because of auto clear
assert_eq!(sparkv.len(), 2);

// auto clear 2
Expand All @@ -259,7 +262,7 @@ fn test_clear_expired_with_auto_clear_expired_enabled() {
"value".into(),
Duration::new(60, 0).expect("a valid duration"),
);
assert_eq!(sparkv.expiries.len(), 4); // should have cleared the expiries
assert_eq!(sparkv.expiries.len(), 3); // should have cleared the expiries
assert_eq!(sparkv.len(), 3); // but not actually deleting
}

Expand Down

0 comments on commit 813b716

Please sign in to comment.