mirror of
https://github.com/openai/codex.git
synced 2026-10-31 19:28:49 +00:00
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:
committed by
copyberry
parent
22db5847c8
commit
c227654800
+1
-1
@@ -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;
|
||||
|
||||
Vendored
+2
-53
@@ -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
@@ -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;
|
||||
Reference in New Issue
Block a user