]> git.lizzy.rs Git - rust.git/commitdiff
use deterministic HashMap in libtest
authorRalf Jung <post@ralfj.de>
Mon, 26 Nov 2018 07:27:36 +0000 (08:27 +0100)
committerRalf Jung <post@ralfj.de>
Tue, 27 Nov 2018 12:59:19 +0000 (13:59 +0100)
src/libtest/lib.rs

index 7c26d042a7ccfbed2c13de0a306848b1bca9d2fe..d59cc293c23089f224f92098a9a9e79da22aaaa5 100644 (file)
@@ -1071,8 +1071,12 @@ pub fn run_tests<F>(opts: &TestOpts, tests: Vec<TestDescAndFn>, mut callback: F)
 where
     F: FnMut(TestEvent) -> io::Result<()>,
 {
-    use std::collections::HashMap;
+    use std::collections::{self, HashMap};
+    use std::hash::BuildHasherDefault;
     use std::sync::mpsc::RecvTimeoutError;
+    // Use a deterministic hasher
+    type TestMap =
+        HashMap<TestDesc, Instant, BuildHasherDefault<collections::hash_map::DefaultHasher>>;
 
     let tests_len = tests.len();
 
@@ -1111,9 +1115,9 @@ pub fn run_tests<F>(opts: &TestOpts, tests: Vec<TestDescAndFn>, mut callback: F)
 
     let (tx, rx) = channel::<MonitorMsg>();
 
-    let mut running_tests: HashMap<TestDesc, Instant> = HashMap::new();
+    let mut running_tests: TestMap = HashMap::default();
 
-    fn get_timed_out_tests(running_tests: &mut HashMap<TestDesc, Instant>) -> Vec<TestDesc> {
+    fn get_timed_out_tests(running_tests: &mut TestMap) -> Vec<TestDesc> {
         let now = Instant::now();
         let timed_out = running_tests
             .iter()
@@ -1131,7 +1135,7 @@ fn get_timed_out_tests(running_tests: &mut HashMap<TestDesc, Instant>) -> Vec<Te
         timed_out
     };
 
-    fn calc_timeout(running_tests: &HashMap<TestDesc, Instant>) -> Option<Duration> {
+    fn calc_timeout(running_tests: &TestMap) -> Option<Duration> {
         running_tests.values().min().map(|next_timeout| {
             let now = Instant::now();
             if *next_timeout >= now {