Consolidate Rust unit tests under dedicated test modules (#56247)

## What changed

Move inline crate tests into `lib_tests.rs` and nest related test suites under each crate's `tests` module. Update imports, subprocess test filters, logging targets, and snapshot names to match the new module paths.

Keep test helpers accessible where needed and preserve the schema writer's exact test name used by release tooling.

GitOrigin-RevId: de55eaae66dce4941abb33dd0b2f170093daa8f9
This commit is contained in:
Dmitriy Kovalenko
2026-10-22 19:36:47 +00:00
committed by copyberry
parent 22db5847c8
commit c227654800
47 changed files with 4100 additions and 4090 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
//! Checks that initialization releases the global lock and survives LRU eviction.
use super::BlockingLruCache;
use crate::BlockingLruCache;
use std::num::NonZeroUsize;
use std::sync::mpsc;
use std::time::Duration;
+2 -53
View File
@@ -163,56 +163,5 @@ pub fn sha1_digest(bytes: &[u8]) -> [u8; 20] {
}
#[cfg(test)]
#[path = "initialization_tests.rs"]
mod initialization_tests;
#[cfg(test)]
mod tests {
use super::BlockingLruCache;
use std::num::NonZeroUsize;
#[tokio::test(flavor = "multi_thread")]
async fn stores_and_retrieves_values() {
let cache = BlockingLruCache::new(NonZeroUsize::new(2).expect("capacity"));
assert!(cache.get(&"first").is_none());
cache.insert("first", /*value*/ 1);
assert_eq!(cache.get(&"first"), Some(1));
}
#[tokio::test(flavor = "multi_thread")]
async fn evicts_least_recently_used() {
let cache = BlockingLruCache::new(NonZeroUsize::new(2).expect("capacity"));
cache.insert("a", /*value*/ 1);
cache.insert("b", /*value*/ 2);
assert_eq!(cache.get(&"a"), Some(1));
cache.insert("c", /*value*/ 3);
assert!(cache.get(&"b").is_none());
assert_eq!(cache.get(&"a"), Some(1));
assert_eq!(cache.get(&"c"), Some(3));
}
#[test]
fn disabled_without_runtime() {
let cache = BlockingLruCache::new(NonZeroUsize::new(2).expect("capacity"));
cache.insert("first", /*value*/ 1);
assert!(cache.get(&"first").is_none());
assert_eq!(cache.get_or_insert_with("first", || 2), 2);
assert!(cache.get(&"first").is_none());
assert!(cache.remove(&"first").is_none());
cache.clear();
let result = cache.with_mut(|inner| {
inner.put("tmp", 3);
inner.get(&"tmp").cloned()
});
assert_eq!(result, Some(3));
assert!(cache.get(&"tmp").is_none());
assert!(cache.blocking_lock().is_none());
}
}
#[path = "lib_tests.rs"]
mod tests;
+54
View File
@@ -0,0 +1,54 @@
#![cfg(test)]
//! Unit tests for the crate and its related test suites.
use super::BlockingLruCache;
use std::num::NonZeroUsize;
#[tokio::test(flavor = "multi_thread")]
async fn stores_and_retrieves_values() {
let cache = BlockingLruCache::new(NonZeroUsize::new(2).expect("capacity"));
assert!(cache.get(&"first").is_none());
cache.insert("first", /*value*/ 1);
assert_eq!(cache.get(&"first"), Some(1));
}
#[tokio::test(flavor = "multi_thread")]
async fn evicts_least_recently_used() {
let cache = BlockingLruCache::new(NonZeroUsize::new(2).expect("capacity"));
cache.insert("a", /*value*/ 1);
cache.insert("b", /*value*/ 2);
assert_eq!(cache.get(&"a"), Some(1));
cache.insert("c", /*value*/ 3);
assert!(cache.get(&"b").is_none());
assert_eq!(cache.get(&"a"), Some(1));
assert_eq!(cache.get(&"c"), Some(3));
}
#[test]
fn disabled_without_runtime() {
let cache = BlockingLruCache::new(NonZeroUsize::new(2).expect("capacity"));
cache.insert("first", /*value*/ 1);
assert!(cache.get(&"first").is_none());
assert_eq!(cache.get_or_insert_with("first", || 2), 2);
assert!(cache.get(&"first").is_none());
assert!(cache.remove(&"first").is_none());
cache.clear();
let result = cache.with_mut(|inner| {
inner.put("tmp", 3);
inner.get(&"tmp").cloned()
});
assert_eq!(result, Some(3));
assert!(cache.get(&"tmp").is_none());
assert!(cache.blocking_lock().is_none());
}
#[path = "initialization_tests.rs"]
mod initialization_tests;