diff options
author | Matthew Gumport <[email protected]> | 2024-06-17 08:50:25 -0700 |
---|---|---|
committer | Matthew (mbg) <[email protected]> | 2024-06-21 09:54:09 -0700 |
commit | 899d86c5d48deb2a01c66e431726e1fda030f48d (patch) | |
tree | 3e3840bdf8085ab6a045fad12995a1efc0b3a63b /tinyufo | |
parent | 02111515c68af63894a76df742e1eb7ce1c48070 (diff) | |
download | pingora-899d86c5d48deb2a01c66e431726e1fda030f48d.tar.gz pingora-899d86c5d48deb2a01c66e431726e1fda030f48d.zip |
change tinyufo test to be deterministic
Previously the test would fail because the item evicted may be the entry (4,4,1)
failing admission. I adjusted the weights so that all weights for items besides
the one we want moved to the main cache are equal and the cache can only hold
three. The test then checks that 1 is moved to the main, the evicted key is
gone, and the other two are present.
Diffstat (limited to 'tinyufo')
-rw-r--r-- | tinyufo/src/lib.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/tinyufo/src/lib.rs b/tinyufo/src/lib.rs index 248f729..805373e 100644 --- a/tinyufo/src/lib.rs +++ b/tinyufo/src/lib.rs @@ -686,14 +686,22 @@ mod tests { assert_eq!(cache.peek_queue(2), Some(SMALL)); assert_eq!(cache.peek_queue(3), Some(SMALL)); - let evicted = cache.put(4, 4, 1); + let evicted = cache.put(4, 4, 2); assert_eq!(evicted.len(), 1); - assert_eq!(evicted[0].data, 2); + assert_eq!(evicted[0].weight, 2); assert_eq!(cache.peek_queue(1), Some(MAIN)); - // 2 is evicted because 1 is in main - assert_eq!(cache.peek_queue(2), None); - assert_eq!(cache.peek_queue(3), Some(SMALL)); - assert_eq!(cache.peek_queue(4), Some(SMALL)); + // either 2, 3, or 4 was evicted. Check evicted for which. + let mut remaining = vec![2, 3, 4]; + remaining.remove( + remaining + .iter() + .position(|x| *x == evicted[0].data) + .unwrap(), + ); + assert_eq!(cache.peek_queue(evicted[0].key), None); + for k in remaining { + assert_eq!(cache.peek_queue(k), Some(SMALL)); + } } } |