From 263771e4030f4fce4a6538d95ed371212172b3b0 Mon Sep 17 00:00:00 2001 From: xfy Date: Tue, 9 Jun 2026 17:24:14 +0800 Subject: [PATCH] test(cache): fix invalidation test isolation --- src/cache.rs | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/cache.rs b/src/cache.rs index d62d3ea..3065d36 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -319,12 +319,34 @@ mod tests { #[tokio::test] async fn cache_invalidation_works() { - let key = CacheKey::PublishedPosts { page: 1, per_page: 10 }; - set_post_list(&key, vec![]).await; + let post = Some(Post { + id: 42, + author_id: 1, + title: "Invalidation Test".to_string(), + slug: "invalidation-test".to_string(), + summary: None, + content_md: "test".to_string(), + content_html: None, + status: PostStatus::Published, + published_at: None, + created_at: chrono::Utc::now(), + updated_at: chrono::Utc::now(), + tags: vec![], + cover_image: None, + reading_time: 1, + word_count: 4, + toc_html: None, + prev_post: None, + next_post: None, + }); - invalidate_post_lists(); + set_post_by_slug("invalidation-test", post.clone()).await; + let cached_before = get_post_by_slug("invalidation-test").await; + assert!(cached_before.is_some()); - let cached = get_post_list(&key).await; - assert!(cached.is_none()); + invalidate_post_by_slug("invalidation-test").await; + + let cached_after = get_post_by_slug("invalidation-test").await; + assert!(cached_after.is_none()); } }