diff --git a/crates/metadata/src/xmp_merge.rs b/crates/metadata/src/xmp_merge.rs
index b52e81c261..2a3be72af0 100644
--- a/crates/metadata/src/xmp_merge.rs
+++ b/crates/metadata/src/xmp_merge.rs
@@ -465,21 +465,36 @@ mod tests {
#[test]
fn many_attributes_scan_in_linear_time() {
// quick-xml's duplicate-name check compares each attribute with all earlier ones: 200 000 attributes on
- // one description took over 20 s to scan, about 30 ms with the set
- let n = 200_000;
- let mut s = String::from(
- "\
- ");
- let t = std::time::Instant::now();
- let found = scan(&s, &[LC]).unwrap();
- let took = t.elapsed();
- assert_eq!(found.descs[0].attrs.len(), n + 2, "every attribute is read");
- assert!(took < std::time::Duration::from_secs(5), "{n} attributes took {took:?}");
+ // one description took over 20 s to scan, about 30 ms with the set. Four times the attributes must take
+ // about four times as long, not sixteen. A ratio of best-of-three times holds on a loaded machine, where
+ // a fixed bound does not.
+ let packet = |n: usize| {
+ let mut s = String::from(
+ "\
+ ");
+ s
+ };
+ let best = |n: usize| {
+ let s = packet(n);
+ (0..3)
+ .map(|_| {
+ let t = std::time::Instant::now();
+ let found = scan(&s, &[]).unwrap();
+ let took = t.elapsed();
+ assert_eq!(found.descs[0].attrs.len(), n + 2, "every attribute is read");
+ took
+ })
+ .min()
+ .unwrap_or_default()
+ };
+ let (small, large) = (best(25_000), best(100_000));
+ let ratio = large.as_secs_f64() / small.as_secs_f64().max(1e-6);
+ assert!(ratio < 10.0, "4x the attributes took {ratio:.1}x as long ({small:?}, then {large:?})");
}
#[test]