Skip to content

Commit 077087a

Browse files
committed
Auto merge of #6274 - Eh2406:small_things, r=alexcrichton
Small things to help with fuzz tests These are some small fixes to make it less likely to have randomly failing tests. This also documents what to do, and not to feel guilty, if the test do fail.
2 parents a83cd61 + 7ca46cc commit 077087a

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/cargo/core/resolver/conflict_cache.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ pub(super) struct ConflictCache {
3535
// unconditionally true regardless of our resolution history of how we got
3636
// here.
3737
con_from_dep: HashMap<Dependency, Vec<HashMap<PackageId, ConflictReason>>>,
38-
// `past_conflict_triggers` is an
39-
// of `past_conflicting_activations`.
40-
// For every `PackageId` this lists the `Dependency`s that mention it in `past_conflicting_activations`.
38+
// `dep_from_pid` is an inverse-index of `con_from_dep`.
39+
// For every `PackageId` this lists the `Dependency`s that mention it in `dep_from_pid`.
4140
dep_from_pid: HashMap<PackageId, HashSet<Dependency>>,
4241
}
4342

@@ -62,6 +61,7 @@ impl ConflictCache {
6261
self.con_from_dep
6362
.get(dep)?
6463
.iter()
64+
.rev() // more general cases are normally found letter. So start the search there.
6565
.filter(filter)
6666
.find(|conflicting| cx.is_conflicting(None, conflicting))
6767
}

tests/testsuite/resolve.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ use support::resolver::{
1515
use proptest::collection::vec;
1616
use proptest::prelude::*;
1717

18+
/// NOTE: proptest is a form of fuzz testing. It generates random input and makes shore that
19+
/// certain universal truths are upheld. Therefore, it can pass when there is a problem,
20+
/// but if it fails then there really is something wrong. When testing something as
21+
/// complicated as the resolver, the problems can be very subtle and hard to generate.
22+
/// We have had a history of these tests only failing on PRs long after a bug is introduced.
23+
/// If you have one of these test fail please report it on #6258,
24+
/// and if you did not change the resolver then feel free to retry without concern.
1825
proptest! {
1926
#![proptest_config(ProptestConfig {
2027
// Note that this is a little low in terms of cases we'd like to test,
@@ -34,6 +41,7 @@ proptest! {
3441
.. ProptestConfig::default()
3542
})]
3643

44+
/// NOTE: if you think this test has failed spuriously see the note at the top of this macro.
3745
#[test]
3846
fn passes_validation(
3947
PrettyPrintRegistry(input) in registry_strategy(50, 20, 60)
@@ -51,6 +59,7 @@ proptest! {
5159
}
5260
}
5361

62+
/// NOTE: if you think this test has failed spuriously see the note at the top of this macro.
5463
#[test]
5564
fn minimum_version_errors_the_same(
5665
PrettyPrintRegistry(input) in registry_strategy(50, 20, 60)
@@ -100,6 +109,7 @@ proptest! {
100109
}
101110
}
102111

112+
/// NOTE: if you think this test has failed spuriously see the note at the top of this macro.
103113
#[test]
104114
fn limited_independence_of_irrelevant_alternatives(
105115
PrettyPrintRegistry(input) in registry_strategy(50, 20, 60),

tests/testsuite/support/resolver.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ pub fn registry_strategy(
355355
max_versions: usize,
356356
shrinkage: usize,
357357
) -> impl Strategy<Value = PrettyPrintRegistry> {
358-
let name = string_regex("[A-Za-z_-][A-Za-z0-9_-]*(-sys)?").unwrap();
358+
let name = string_regex("[A-Za-z][A-Za-z0-9_-]*(-sys)?").unwrap();
359359

360360
let raw_version = [..max_versions; 3];
361361
let version_from_raw = |v: &[usize; 3]| format!("{}.{}.{}", v[0], v[1], v[2]);
@@ -460,12 +460,16 @@ pub fn registry_strategy(
460460

461461
/// This test is to test the generator to ensure
462462
/// that it makes registries with large dependency trees
463+
///
464+
/// This is a form of randomized testing, if you are unlucky it can fail.
465+
/// A failure on it's own is not a big dael. If you did not change the
466+
/// `registry_strategy` then feel free to retry without concern.
463467
#[test]
464468
fn meta_test_deep_trees_from_strategy() {
465469
let mut dis = [0; 21];
466470

467471
let strategy = registry_strategy(50, 20, 60);
468-
for _ in 0..64 {
472+
for _ in 0..128 {
469473
let PrettyPrintRegistry(input) = strategy
470474
.new_tree(&mut TestRunner::default())
471475
.unwrap()
@@ -488,19 +492,23 @@ fn meta_test_deep_trees_from_strategy() {
488492
}
489493

490494
panic!(
491-
"In 640 tries we did not see a wide enough distribution of dependency trees! dis: {:?}",
495+
"In 1280 tries we did not see a wide enough distribution of dependency trees! dis: {:?}",
492496
dis
493497
);
494498
}
495499

496500
/// This test is to test the generator to ensure
497501
/// that it makes registries that include multiple versions of the same library
502+
///
503+
/// This is a form of randomized testing, if you are unlucky it can fail.
504+
/// A failure on its own is not a big deal. If you did not change the
505+
/// `registry_strategy` then feel free to retry without concern.
498506
#[test]
499507
fn meta_test_multiple_versions_strategy() {
500508
let mut dis = [0; 10];
501509

502510
let strategy = registry_strategy(50, 20, 60);
503-
for _ in 0..64 {
511+
for _ in 0..128 {
504512
let PrettyPrintRegistry(input) = strategy
505513
.new_tree(&mut TestRunner::default())
506514
.unwrap()
@@ -524,7 +532,7 @@ fn meta_test_multiple_versions_strategy() {
524532
}
525533
}
526534
panic!(
527-
"In 640 tries we did not see a wide enough distribution of multiple versions of the same library! dis: {:?}",
535+
"In 1280 tries we did not see a wide enough distribution of multiple versions of the same library! dis: {:?}",
528536
dis
529537
);
530538
}

0 commit comments

Comments
 (0)