Skip to content

Commit

Permalink
test(runtime-config): Add some tests to make sure data is cached
Browse files Browse the repository at this point in the history
  • Loading branch information
john-z-yang committed Nov 20, 2024
1 parent feffb16 commit 0fe75cd
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions rust_snuba/src/runtime_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub fn get_str_config(key: &str) -> Result<Option<String>, Error> {

#[cfg(test)]
mod tests {
use std::thread;

use super::*;

#[test]
Expand All @@ -48,4 +50,39 @@ mod tests {
let config = get_str_config("test");
assert_eq!(config.unwrap(), None);
}

#[test]
fn test_runtime_config_is_stored_in_cache() {
crate::testutils::initialize_python();
let config = get_str_config("test");
assert_eq!(config.unwrap(), None);
assert!(CONFIG.read().contains_key("test"));
}

#[test]
fn test_runtime_config_retrieves_from_cache_within_deadline() {
CONFIG.write().insert(
"key".to_string(),
(
Some("value".to_string()),
Deadline::new(Duration::from_secs(10)),
),
);
let config = get_str_config("key");
assert_eq!(config.unwrap(), Some("value".to_string()));
CONFIG.write().clear();
}

#[test]
fn test_runtime_config_invalidates_cache_outside_deadline() {
CONFIG.write().insert(
"key".to_string(),
(
Some("value".to_string()),
Deadline::new(Duration::from_secs(0)),
),
);
let config = get_str_config("key");
assert_eq!(config.unwrap(), None);
}
}

0 comments on commit 0fe75cd

Please sign in to comment.