-
Notifications
You must be signed in to change notification settings - Fork 4
test(cache): reproduce foyer disk reinsertion corruption #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -688,6 +688,7 @@ mod tests { | |
| //! Cache-level integration tests for `HybridArticleCache` | ||
| //! | ||
| use super::*; | ||
| use std::sync::Arc; | ||
|
|
||
| #[test] | ||
| fn hybrid_cache_name_cold_invalidates_old_disk_formats() { | ||
|
|
@@ -982,4 +983,83 @@ mod tests { | |
|
|
||
| cache.close().await.unwrap(); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread", worker_threads = 8)] | ||
| async fn hybrid_disk_reinsertion_does_not_corrupt_lru() { | ||
| const KEYS: u64 = 64; | ||
| const WORKERS: u64 = 32; | ||
|
|
||
| let disk_dir = tempfile::tempdir().unwrap(); | ||
| let cache = Arc::new( | ||
| HybridArticleCache::new(HybridCacheConfig { | ||
| memory_capacity: 256 * 1024, | ||
| disk_capacity: 128 * 1024 * 1024, | ||
| disk_path: disk_dir.path().to_path_buf(), | ||
| ttl: Duration::from_secs(60 * 60), | ||
| compression: CompressionCodec::None, | ||
| shards: 1, | ||
| }) | ||
| .await | ||
| .unwrap(), | ||
| ); | ||
|
|
||
| for key in 0..KEYS * 2 { | ||
| let message_id = format!("<lru-reinsert-{key}@example.com>"); | ||
| let response = format!( | ||
| "220 0 {message_id} article\r\n\r\n{}\r\n.\r\n", | ||
| "x".repeat(4096) | ||
| ) | ||
| .into_bytes(); | ||
| cache | ||
| .upsert_ingest( | ||
| MessageId::from_borrowed(&message_id).unwrap(), | ||
| response, | ||
| BackendId::from_index(0), | ||
| 0.into(), | ||
| ) | ||
| .await; | ||
| } | ||
|
|
||
| tokio::time::sleep(Duration::from_secs(1)).await; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Prove that the workload reaches the disk tier.
🤖 Prompt for AI Agents |
||
| let deadline = tokio::time::Instant::now() + Duration::from_secs(10); | ||
| let mut workers = Vec::new(); | ||
|
|
||
| for worker in 0..WORKERS { | ||
| let cache = Arc::clone(&cache); | ||
| workers.push(tokio::spawn(async move { | ||
| let mut state = worker + 1; | ||
| while tokio::time::Instant::now() < deadline { | ||
| state ^= state << 13; | ||
| state ^= state >> 7; | ||
| state ^= state << 17; | ||
| let key = state % (KEYS * 2); | ||
| let message_id = format!("<lru-reinsert-{key}@example.com>"); | ||
| let message_id_ref = MessageId::from_borrowed(&message_id).unwrap(); | ||
|
|
||
| if state % 10 < 7 { | ||
| let _ = cache.get(&message_id_ref).await; | ||
| } else { | ||
| let response = format!( | ||
| "220 0 {message_id} article\r\n\r\n{}\r\n.\r\n", | ||
| "x".repeat(4096) | ||
| ) | ||
| .into_bytes(); | ||
| cache | ||
| .upsert_ingest( | ||
| message_id_ref, | ||
| response, | ||
| BackendId::from_index(0), | ||
| 0.into(), | ||
| ) | ||
| .await; | ||
| } | ||
| } | ||
| })); | ||
| } | ||
|
|
||
| for worker in workers { | ||
| worker.await.unwrap(); | ||
| } | ||
| cache.close().await.unwrap(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Remove raw multiline terminators from this cache test.
Lines 1009 and 1043 encode
\r\n.\r\noutsideMultilineFramer. This makes the cache test another owner of NNTP response termination rules. Build the fixture through a framing or protocol helper that owns multiline encoding.As per coding guidelines, “Only
src/session/multiline_framing.rsmay know how NNTP multiline responses end.”Also applies to: 1043-1043
🤖 Prompt for AI Agents
Source: Coding guidelines