Skip to content

Commit

Permalink
--amend
Browse files Browse the repository at this point in the history
(cherry picked from commit ad3cb0b)
  • Loading branch information
t-nelson authored and mergify-bot committed Jan 8, 2022
1 parent 4d085d6 commit 781a0aa
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion runtime/src/bank.rs
Expand Up @@ -361,7 +361,7 @@ struct CachedExecutorsEntry {
struct CachedExecutors {
max: usize,
current_epoch: Epoch,
executors: HashMap<Pubkey, CachedExecutorsEntry>,
pub(self) executors: HashMap<Pubkey, CachedExecutorsEntry>,
stats: executor_cache::Stats,
}
impl Default for CachedExecutors {
Expand Down Expand Up @@ -12007,6 +12007,35 @@ pub(crate) mod tests {
assert!(cache.get(&key3).is_some());
}

#[test]
fn test_cached_executors_evicts_smallest() {
let key1 = solana_sdk::pubkey::new_rand();
let key2 = solana_sdk::pubkey::new_rand();
let key3 = solana_sdk::pubkey::new_rand();
let executor: Arc<dyn Executor> = Arc::new(TestExecutor {});
let mut cache = CachedExecutors::new(2, 0);

cache.put(&key1, executor.clone());
for _ in 0..5 {
let _ = cache.get(&key1);
}
cache.put(&key2, executor.clone());
// make key1's use-count for sure greater than key2's
let _ = cache.get(&key1);

let mut entries = cache
.executors
.iter()
.map(|(k, v)| (*k, v.epoch_count.load(Relaxed)))
.collect::<Vec<_>>();
entries.sort_by_key(|(_, v)| *v);
assert!(entries[0].1 < entries[1].1);

cache.put(&key3, executor.clone());
assert!(cache.get(&entries[0].0).is_none());
assert!(cache.get(&entries[1].0).is_some());
}

#[test]
fn test_bank_executor_cache() {
solana_logger::setup();
Expand Down

0 comments on commit 781a0aa

Please sign in to comment.