From 0cf73c4a1c7a5ed9c14fd4614a1d435ddbd8f53b Mon Sep 17 00:00:00 2001 From: teor Date: Fri, 6 Dec 2024 08:29:05 +1000 Subject: [PATCH] Add tests for MostSeen decrement bug This bug requires a specific set of circumstances to trigger and become visible: 1. decrement a label that is non-zero but not first 2. repeat the decrement at least best_count()/2 times 3. increment that label 4. check the best count --- backend/common/src/most_seen.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/common/src/most_seen.rs b/backend/common/src/most_seen.rs index 2d4d81ff..15f50ea6 100644 --- a/backend/common/src/most_seen.rs +++ b/backend/common/src/most_seen.rs @@ -248,5 +248,11 @@ mod test { assert!(res.has_changed()); assert_eq!(a.best_count(), 2); assert_eq!(*a.best(), "First"); // First is now ahead + + a.remove(&"Third"); // 0, or 2 with bug #595 + a.remove(&"Third"); // 0, or 4 with bug #595 + a.insert(&"Third"); // 1, or 5 with bug #595 + assert_eq!(a.best_count(), 2); + assert_eq!(*a.best(), "First"); // First is still ahead } }