Skip to content

Commit

Permalink
Fix failing memory table tests
Browse files Browse the repository at this point in the history
  • Loading branch information
esensar committed Dec 4, 2024
1 parent e17880a commit 5c6f7ac
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/enrichment_tables/memory/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ mod tests {
test_util::components::{run_and_assert_sink_compliance, SINK_TAGS},
};

fn build_memory_config(modfn: impl Fn(&mut MemoryConfig)) -> MemoryConfig {
let mut config = MemoryConfig::default();
modfn(&mut config);
config
}

#[test]
fn finds_row() {
let mut memory = Memory::new(Default::default());
Expand All @@ -295,10 +301,7 @@ mod tests {
fn calculates_ttl() {
let ttl = 100;
let secs_to_subtract = 10;
let memory = Memory::new(MemoryConfig {
ttl,
..Default::default()
});
let memory = Memory::new(build_memory_config(|c| c.ttl = ttl));
{
let mut handle = memory.write_handle.lock().unwrap();
handle.update(
Expand Down Expand Up @@ -330,11 +333,10 @@ mod tests {
#[test]
fn removes_expired_records_on_scan_interval() {
let ttl = 100;
let mut memory = Memory::new(MemoryConfig {
ttl,
scan_interval: 0,
..Default::default()
});
let mut memory = Memory::new(build_memory_config(|c| {
c.ttl = ttl;
c.scan_interval = 0;
}));
{
let mut handle = memory.write_handle.lock().unwrap();
handle.update(
Expand Down Expand Up @@ -376,11 +378,10 @@ mod tests {
#[test]
fn does_not_show_values_before_flush_interval() {
let ttl = 100;
let mut memory = Memory::new(MemoryConfig {
ttl,
flush_interval: 10,
..Default::default()
});
let mut memory = Memory::new(build_memory_config(|c| {
c.ttl = ttl;
c.flush_interval = 10;
}));
memory.handle_value(&ObjectMap::from([("test_key".into(), Value::from(5))]));

let condition = Condition::Equals {
Expand All @@ -398,10 +399,7 @@ mod tests {
#[test]
fn updates_ttl_on_value_replacement() {
let ttl = 100;
let mut memory = Memory::new(MemoryConfig {
ttl,
..Default::default()
});
let mut memory = Memory::new(build_memory_config(|c| c.ttl = ttl));
{
let mut handle = memory.write_handle.lock().unwrap();
handle.update(
Expand Down

0 comments on commit 5c6f7ac

Please sign in to comment.