Skip to content

Commit feaa75d

Browse files
committed
test: add a test showing a slow case in the resolver
1 parent ac39e69 commit feaa75d

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

crates/resolver-tests/tests/resolve.rs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use cargo::util::GlobalContext;
44

55
use resolver_tests::{
66
helpers::{
7-
assert_contains, assert_same, dep, dep_kind, dep_loc, dep_req, loc_names, names, pkg_id,
8-
pkg_loc, registry, ToPkgId,
7+
assert_contains, assert_same, dep, dep_kind, dep_loc, dep_req, loc_names, names, pkg,
8+
pkg_dep, pkg_dep_with, pkg_id, pkg_loc, registry, ToDep, ToPkgId,
99
},
1010
pkg, resolve, resolve_with_global_context,
1111
};
@@ -937,6 +937,50 @@ fn large_conflict_cache() {
937937
let _ = resolve(root_deps, &reg);
938938
}
939939

940+
#[test]
941+
fn resolving_slow_case_missing_feature() {
942+
let mut reg = Vec::new();
943+
944+
const LAST_CRATE_VERSION_COUNT: usize = 50;
945+
946+
// increase in resolve time is at least cubic over `INTERMEDIATE_CRATES_VERSION_COUNT`.
947+
// it should be `>= LAST_CRATE_VERSION_COUNT` to reproduce slowdown.
948+
const INTERMEDIATE_CRATES_VERSION_COUNT: usize = LAST_CRATE_VERSION_COUNT + 5;
949+
950+
// should be `>= 2` to reproduce slowdown
951+
const TRANSITIVE_CRATES_COUNT: usize = 3;
952+
953+
reg.push(pkg_dep_with(("last", "1.0.0"), vec![], &[("f", &[])]));
954+
for v in 1..LAST_CRATE_VERSION_COUNT {
955+
reg.push(pkg(("last", format!("1.0.{v}"))));
956+
}
957+
958+
reg.push(pkg_dep(
959+
("dep", "1.0.0"),
960+
vec![
961+
dep("last"), // <-- needed to reproduce slowdown
962+
dep_req("intermediate-1", "1.0.0"),
963+
],
964+
));
965+
966+
for n in 0..INTERMEDIATE_CRATES_VERSION_COUNT {
967+
let version = format!("1.0.{n}");
968+
for c in 1..TRANSITIVE_CRATES_COUNT {
969+
reg.push(pkg_dep(
970+
(format!("intermediate-{c}"), &version),
971+
vec![dep_req(&format!("intermediate-{}", c + 1), &version)],
972+
));
973+
}
974+
reg.push(pkg_dep(
975+
(format!("intermediate-{TRANSITIVE_CRATES_COUNT}"), &version),
976+
vec![dep_req("last", "1.0.0").with(&["f"])],
977+
));
978+
}
979+
980+
let deps = vec![dep("dep")];
981+
let _ = resolve(deps, &reg);
982+
}
983+
940984
#[test]
941985
fn cyclic_good_error_message() {
942986
let input = vec![

0 commit comments

Comments
 (0)