denoland / std

The Deno Standard Library
https://jsr.io/@std
MIT License
3.11k stars 614 forks source link

[fs] MacOs : flaky copy test #421

Closed zekth closed 3 years ago

zekth commented 5 years ago

test [fs] copy synchronously with preserve timestamps ... ‌FAILED‌
Error: 

    ‌[Diff]‌ ‌Left‌ / ‌Right‌

-   1558364063‌
+   1558364062‌

    at assertEquals (/Users/vsts/agent/2.150.3/work/1/s/testing/pretty.ts:66:11)
    at assertEquals (/Users/vsts/agent/2.150.3/work/1/s/testing/asserts.ts:64:5)
    at /Users/vsts/agent/2.150.3/work/1/s/fs/copy_test.ts:185:5
    at fn (/Users/vsts/agent/2.150.3/work/1/s/fs/copy_test.ts:32:13)
    at runTestsSerial (/Users/vsts/agent/2.150.3/work/1/s/testing/mod.ts:112:19)
    at async runTests (/Users/vsts/agent/2.150.3/work/1/s/testing/mod.ts:147:9)
    at async main (/Users/vsts/agent/2.150.3/work/1/s/testing/main.ts:5:5)

Sometimes it happens randomly on MacOs.

cc @axetroy

axetroy commented 5 years ago

This should be a bug for Deno.utime

Loss of precision when changing timestamps using Deno.utime

axetroy commented 5 years ago

I tried it, deno.stat() does not change the file's accessed attribute.

So whenever you access, you get consistent properties.

Let's try

// a.ts
const s = Deno.statSync('./test.ts');

console.log(s.created, s.accessed, s.modified);
> deno run --allow-all a.ts
1558369133 1558369638 1558369133
> deno run --allow-all a.ts
1558369133 1558369638 1558369133
> deno run --allow-all a.ts
1558369133 1558369638 1558369133
> deno run --allow-all a.ts
1558369133 1558369638 1558369133

Source Code

https://github.com/denoland/deno_std/blob/301c12d9d20d94d0ed36a394353835a90b5e9249/fs/copy.ts#L87-L94

Conclusion

I guess the problem does not appear in the copy module, but in Deno.utime()