Skip to content

Commit

Permalink
Merge branch 'andriy/run-849-move-tests' into 'master'
Browse files Browse the repository at this point in the history
chore: RUN-849: Move query cache tests into a separate module

There will be more quire cache tests, so it's better to move them into a separate module. 

See merge request dfinity-lab/public/ic!16619
  • Loading branch information
dfinity-berestovskyy committed Dec 11, 2023
2 parents 7e3f663 + 53abecd commit f45daff
Show file tree
Hide file tree
Showing 3 changed files with 920 additions and 906 deletions.
30 changes: 3 additions & 27 deletions rs/execution_environment/src/query_handler/query_cache.rs
Expand Up @@ -9,6 +9,9 @@ use std::{mem::size_of_val, sync::Mutex};

use crate::metrics::duration_histogram;

#[cfg(test)]
mod tests;

////////////////////////////////////////////////////////////////////////
/// Query Cache metrics.
pub(crate) struct QueryCacheMetrics {
Expand Down Expand Up @@ -274,30 +277,3 @@ impl QueryCache {
evicted_entries
}
}

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

use ic_state_machine_tests::WasmResult;
use ic_types::{time, Cycles};

use super::{EntryEnv, EntryValue};

#[test]
fn query_cache_entry_value_elapsed_seconds() {
let current_time = time::GENESIS;
let entry_env = EntryEnv {
batch_time: current_time,
canister_version: 1,
canister_balance: Cycles::new(0),
};
let entry_value = EntryValue::new(entry_env, Result::Ok(WasmResult::Reply(vec![])));
let forward_time = current_time + Duration::from_secs(2);
assert_eq!(2.0, entry_value.elapsed_seconds(forward_time));

// Negative time differences should give just 0.
let backward_time = current_time.saturating_sub_duration(Duration::from_secs(2));
assert_eq!(0.0, entry_value.elapsed_seconds(backward_time));
}
}

0 comments on commit f45daff

Please sign in to comment.