Ask improve_level for more than the test identity already has

ts::identity::tests::improve_level_keeps_the_key made its identity with
Identity::create(), which stops at the first counter whose level is 8 or more,
and asked improve_level for 13. About one identity in 32 has 13 or more
already, and improve_level then returns it as it is, so the assertion that the
counter grew failed: 8 failures in 300 runs of the single test before this
change, 0 in 300 after.

The target is now three levels above what the identity has, so the search
always runs. The assertions on the level, the callbacks and the counter use
that target.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-24 14:21:22 +03:00
1 parent 96ff0e0028
commit 9254e08daa
1 file changed
+7 -3
+7 -3
View File
@@ -672,15 +672,19 @@ mod tests {
#[test]
fn improve_level_keeps_the_key() {
let identity = synthetic();
// A fresh identity stops at the first counter whose level is 8 or more,
// and about one in 32 has 13 or more already, which `improve_level`
// returns as it is: ask for more than this one has, whatever it has.
let target = identity.level() + 3;
let levels = std::sync::Mutex::new(Vec::new());
let better = improve_level(&identity, 13, &AtomicBool::new(false), |l| {
let better = improve_level(&identity, target, &AtomicBool::new(false), |l| {
levels.lock().unwrap().push(l);
})
.unwrap();
assert!(better.level() >= 13);
assert!(better.level() >= target);
assert_eq!(better.key().to_pub().get_uid(), identity.key().to_pub().get_uid());
assert!(better.counter() > identity.counter());
assert!(levels.into_inner().unwrap().iter().any(|l| *l >= 13));
assert!(levels.into_inner().unwrap().iter().any(|l| *l >= target));
// Cancelled: nothing.
assert!(improve_level(&identity, 60, &AtomicBool::new(true), |_| {}).is_none());
// Already there: the same identity.