@@ -4,8 +4,8 @@ use cargo::util::GlobalContext;
44
55use 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,46 @@ fn large_conflict_cache() {
937937 let _ = resolve ( root_deps, & reg) ;
938938}
939939
940+ #[ test]
941+ fn resolving_worst_case ( ) {
942+ let mut reg = Vec :: new ( ) ;
943+
944+ // increase in resolve time is at least cubic over `N`
945+ const V : usize = 50 ;
946+ const N : usize = 50 ; // <-- we should have `N >= V` to reproduce slowdown
947+ const C : usize = 3 ; // <-- we should have `C >= 2` to reproduce slowdown
948+
949+ reg. push ( pkg_dep_with ( ( "cc" , "1.0.0" ) , vec ! [ ] , & [ ( "f" , & [ ] ) ] ) ) ;
950+ for v in 1 ..V {
951+ reg. push ( pkg ( ( "cc" , format ! ( "1.0.{v}" ) ) ) ) ;
952+ }
953+
954+ reg. push ( pkg_dep (
955+ ( "solana-core" , "1.0.0" ) ,
956+ vec ! [
957+ dep( "cc" ) , // <-- needed to reproduce slowdown
958+ dep_req( "solana-1" , "1.0.0" ) ,
959+ ] ,
960+ ) ) ;
961+
962+ for n in 0 ..N {
963+ let version = format ! ( "1.0.{n}" ) ;
964+ for c in 1 ..C {
965+ reg. push ( pkg_dep (
966+ ( format ! ( "solana-{c}" ) , & version) ,
967+ vec ! [ dep_req( & format!( "solana-{}" , c + 1 ) , & version) ] ,
968+ ) ) ;
969+ }
970+ reg. push ( pkg_dep (
971+ ( format ! ( "solana-{C}" ) , & version) ,
972+ vec ! [ dep_req( "cc" , "1.0.0" ) . with( & [ "f" ] ) ] ,
973+ ) ) ;
974+ }
975+
976+ let deps = vec ! [ dep( "solana-core" ) ] ;
977+ let _ = resolve ( deps, & reg) ;
978+ }
979+
940980#[ test]
941981fn cyclic_good_error_message ( ) {
942982 let input = vec ! [
0 commit comments