Commit b44edc5 1 parent e591b0e commit b44edc5 Copy full SHA for b44edc5
File tree 1 file changed +13
-1
lines changed
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ use std::fmt::Write;
22
22
use std:: path:: Path ;
23
23
use std:: path:: PathBuf ;
24
24
use std:: process:: Stdio ;
25
+ use std:: sync:: OnceLock ;
25
26
use std:: time:: { Duration , SystemTime } ;
26
27
27
28
/// Helper to create a simple `foo` project which depends on a registry
@@ -72,7 +73,18 @@ fn get_git_checkout_names(db_name: &str) -> Vec<String> {
72
73
}
73
74
74
75
fn days_ago ( n : u64 ) -> SystemTime {
75
- SystemTime :: now ( ) - Duration :: from_secs ( 60 * 60 * 24 * n)
76
+ now ( ) - Duration :: from_secs ( 60 * 60 * 24 * n)
77
+ }
78
+
79
+ fn now ( ) -> SystemTime {
80
+ // This captures the time once to avoid potential time boundaries or
81
+ // inconsistencies affecting a test. For example, on a fast system
82
+ // `days_ago(1)` called twice in a row will return the same answer.
83
+ // However, on a slower system, or if the clock happens to flip over from
84
+ // one second to the next, then it would return different answers. This
85
+ // ensures that it always returns the same answer.
86
+ static START : OnceLock < SystemTime > = OnceLock :: new ( ) ;
87
+ * START . get_or_init ( || SystemTime :: now ( ) )
76
88
}
77
89
78
90
/// Helper for simulating running cargo in the past. Use with the
You can’t perform that action at this time.
0 commit comments