@@ -4,7 +4,7 @@ use std::path::Path;
4
4
#[ test]
5
5
fn journey ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
6
6
let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
7
- if !has_nanosecond_times ( tmp. path ( ) ) ? {
7
+ if !has_granular_times ( tmp. path ( ) ) ? {
8
8
return Ok ( ( ) ) ;
9
9
}
10
10
@@ -41,17 +41,28 @@ fn journey() -> Result<(), Box<dyn std::error::Error>> {
41
41
Ok ( ( ) )
42
42
}
43
43
44
- fn has_nanosecond_times ( root : & Path ) -> std:: io:: Result < bool > {
45
- let test_file = root . join ( "nanosecond-test" ) ;
44
+ fn has_granular_times ( root : & Path ) -> std:: io:: Result < bool > {
45
+ let n = 50 ;
46
46
47
- std:: fs:: write ( & test_file, "a" ) ?;
48
- let first_time = test_file. metadata ( ) ?. modified ( ) ?;
49
-
50
- std:: fs:: write ( & test_file, "b" ) ?;
51
- let second_time = test_file. metadata ( ) ?. modified ( ) ?;
47
+ let paths = ( 0 ..n) . map ( |i| root. join ( format ! ( "{i:03}" ) ) ) ;
48
+ for ( index, path) in paths. clone ( ) . enumerate ( ) {
49
+ std:: fs:: write ( & path, index. to_string ( ) . as_bytes ( ) ) ?;
50
+ }
51
+ let mut times = Vec :: new ( ) ;
52
+ for path in paths {
53
+ times. push ( path. symlink_metadata ( ) ?. modified ( ) ?) ;
54
+ }
55
+ times. sort ( ) ;
56
+ times. dedup ( ) ;
52
57
53
- Ok ( second_time. duration_since ( first_time) . is_ok_and ( |d|
54
- // This can be falsely false if a filesystem would be ridiculously fast,
55
- // which means a test won't run even though it could. But that's OK, and unlikely.
56
- d. subsec_nanos ( ) != 0 ) )
58
+ // This could be wrongly false if a filesystem has very precise timings yet is ridiculously
59
+ // fast. Then the `journey` test wouldn't run, though it could. But that's OK, and unlikely.
60
+ if cfg ! ( target_os = "macos" ) && is_ci:: cached ( ) {
61
+ assert_eq ! (
62
+ times. len( ) ,
63
+ n,
64
+ "should have very granular timestamps at least on macOS on CI"
65
+ ) ;
66
+ }
67
+ Ok ( times. len ( ) == n)
57
68
}
0 commit comments