coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

Tests failing on a clean repository clone

Open nouritsu opened this issue 2 years ago • 17 comments

Replicate -

  • Run git clone https://github.com/uutils/coreutils && cd coreutils && cargo test
  • Read message returned by cargo test

Host specs -

  • Windows 11 64-bit Latest (as of 3rd August 2023)
  • AMD Ryzen 5 3600x
  • 16GB 3800MHz RAM
  • Used PowerShell in VS Code

nouritsu avatar Aug 03 '23 08:08 nouritsu

What is the message from cargo test? (I don't have access to a windows machine at the moment)

tertsdiepraam avatar Aug 03 '23 08:08 tertsdiepraam

Attached the message from cargo test, used

cargo test > out.txt

out.txt

nouritsu avatar Aug 03 '23 09:08 nouritsu

Note that stderr only reports compiles, module runs and test rerun message ; hence not included in the text file. image

nouritsu avatar Aug 03 '23 09:08 nouritsu

Right, so touch is consistently 10800 seconds (3 hours) off from the expected value? Are you in a timezone that's a 3 hour offset from UTC?

tertsdiepraam avatar Aug 03 '23 09:08 tertsdiepraam

I'm in India, which has the IST time zone. It is UTC + 5:30 Here is a screenshot from windows settings - image

nouritsu avatar Aug 03 '23 09:08 nouritsu

Oh very interesting, I guess it might not be timezone-related then or maybe it is, but in some more complicated way 🤔

tertsdiepraam avatar Aug 03 '23 09:08 tertsdiepraam

The problem may be with chrono getting the incorrect time for whatever reason. Would you like me to run some code that would allow us to rule chrono out?

nouritsu avatar Aug 03 '23 09:08 nouritsu

That would be great! I was thinkin the culprit could be the conversion from chrono to filetime. But yeah, let's rule chrono out first.

tertsdiepraam avatar Aug 03 '23 09:08 tertsdiepraam

I'm not familiar with the crate but I ran this code -

use chrono::prelude::*;

fn main() {
    let local = Local::now();
    println!("{:?}", local);
}

Using chrono v0.4.26.

Output - image This seems to be correct

nouritsu avatar Aug 03 '23 09:08 nouritsu

A little reading later, I think I understand how to test if chrono to filetime is an issue. Here is the code -

use chrono::prelude::*;
use filetime::FileTime;
use std::time::{SystemTime, UNIX_EPOCH};

fn main() {
    let ftime = datetime_to_filetime(&Local::now()).unix_seconds();
    let stime = SystemTime::now()
        .duration_since(UNIX_EPOCH)
        .unwrap()
        .as_secs();
    println!("{}\t{}", ftime, stime);
}

fn datetime_to_filetime<T: TimeZone>(dt: &DateTime<T>) -> FileTime {
    FileTime::from_unix_time(dt.timestamp(), dt.timestamp_subsec_nanos())
}

Prints the following -

1691056504      1691056504

Note that it is 15:25 3rd August 2023

nouritsu avatar Aug 03 '23 09:08 nouritsu

So that's correct? Just as a sanity check, could you run one of the failing test cases manually in the terminal and check whether the time is correct? It might be an issue with the tests, instead of an issue with touch.

tertsdiepraam avatar Aug 03 '23 09:08 tertsdiepraam

Executing command -

coreutils pr --pages=3:5 --column=3 -a -n ".\tests\fixtures\pr\column.log" > pr.txt

Test - test_pr::test_with_column_across_option Times seem to be wrong. pr.txt

nouritsu avatar Aug 03 '23 10:08 nouritsu

Running the command again a few minutes later displayed the time as following (in the output) Aug 03 13:18 2023 Whereas it should be Aug 03 15:44 2023

nouritsu avatar Aug 03 '23 10:08 nouritsu

Strange, we don't do much in pr, just formatting the last modified time. Could you maybe try a small program that just gets a system time, converts it to DateTime<Local> and formats it (like pr does)?

Maybe the conversion from system time to chrono is wrong?

tertsdiepraam avatar Aug 03 '23 10:08 tertsdiepraam

Yes,

use chrono::prelude::*;
use filetime::FileTime;
use std::time::SystemTime;

const DATE_TIME_FORMAT: &str = "%b %d %H:%M %Y";

fn main() {
    let time: DateTime<Local> = SystemTime::now().into();
    println!("{}", time.format(DATE_TIME_FORMAT));
}

outputs

Aug 03 18:12 2023

Which is correct

nouritsu avatar Aug 03 '23 12:08 nouritsu

Any idea why this was failing? I'd love to test this again tomorrow and close this issue.

nouritsu avatar Jan 26 '24 20:01 nouritsu

I'm still not sure to be honest

tertsdiepraam avatar Jan 27 '24 13:01 tertsdiepraam