From 778f37b12d7a16f368e5be4580a984fe2265983a Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 13 Oct 2021 20:02:42 +0000 Subject: [PATCH] fix unstable test (#20645) (#20663) (cherry picked from commit 220fd41bbc5fc338358562f48238bc82a13d237b) Co-authored-by: Tao Zhu <82401714+taozhu-chicago@users.noreply.github.com> --- runtime/src/execute_cost_table.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/runtime/src/execute_cost_table.rs b/runtime/src/execute_cost_table.rs index 81dfac8d74..4f0b3e9645 100644 --- a/runtime/src/execute_cost_table.rs +++ b/runtime/src/execute_cost_table.rs @@ -185,14 +185,19 @@ mod tests { let key2 = Pubkey::new_unique(); let key3 = Pubkey::new_unique(); - testee.upsert(&key1, 1); - testee.upsert(&key1, 1); + // simulate a lot of occurences to key1, so even there're longer than + // usual delay between upsert(key1..) and upsert(key2, ..), test + // would still satisfy as key1 has enough occurences to compensate + // its age. + for i in 0..1000 { + testee.upsert(&key1, i); + } testee.upsert(&key2, 2); testee.upsert(&key3, 3); testee.prune_to(&(capacity - 1)); - // the oldest, key1, has 2 counts; 2nd oldest Key2 has 1 count; + // the oldest, key1, has many counts; 2nd oldest Key2 has 1 count; // expect key2 to be pruned. assert!(testee.get_cost(&key1).is_some()); assert!(testee.get_cost(&key2).is_none());