@@ -4,7 +4,7 @@ use std::path::Path;
44#[ test]
55fn journey ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
66 let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
7- if !has_nanosecond_times ( tmp. path ( ) ) ? {
7+ if !has_granular_times ( tmp. path ( ) ) ? {
88 return Ok ( ( ) ) ;
99 }
1010
@@ -41,17 +41,28 @@ fn journey() -> Result<(), Box<dyn std::error::Error>> {
4141 Ok ( ( ) )
4242}
4343
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 ;
4646
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 ( ) ;
5257
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)
5768}
0 commit comments