-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: fix time resolution constrain #3981
Conversation
@@ -23,7 +23,7 @@ function check_mtime(resource, mtime) { | |||
var real_mtime = fs._toUnixTimestamp(stats.mtime); | |||
// check up to single-second precision | |||
// sub-second precision is OS and fs dependant | |||
return Math.floor(mtime) == Math.floor(real_mtime); | |||
return (Math.floor(mtime) - Math.floor(real_mtime) <= 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest Math.floor(mtime - real_mtime) <= 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just mtime - real_mtime < 2
?
Thanks @JungMinu and @bnoordhuis . I will try both, and get back with observations, |
The modification time of a file is assumed to happen at the exact time when it was requested. As the utime API specification delcares that the resolution of the result is 1 second, relax the constrain to 1 second helps the test case to be robust and consistent under different load conditions in the system
Both are working, picked up @bnoordhuis' suggestion as it is more compact. Please review and do the needful. Thanks! |
I'm a little late, but LGTM, and appreciate the detailed write up. |
LGTM |
@JungMinu Did you land this? Commit e918224 doesn't seem to belong to any branch. Aside, there's a small typo in the commit log: s/constrain/constraint/ |
@bnoordhuis sorry to bug you, I will handle it now |
The modification time of a file is assumed to happen at the exact time when it was requested. As the utime API specification delcares that the resolution of the result is 1 second, relax the constrain to 1 second helps the test case to be robust and consistent under different load conditions in the system PR-URL: #3981 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
Thanks, Landed in cf65299 |
The modification time of a file is assumed to happen at the exact time when it was requested. As the utime API specification delcares that the resolution of the result is 1 second, relax the constrain to 1 second helps the test case to be robust and consistent under different load conditions in the system PR-URL: #3981 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
The modification time of a file is assumed to happen at the exact time when it was requested. As the utime API specification delcares that the resolution of the result is 1 second, relax the constrain to 1 second helps the test case to be robust and consistent under different load conditions in the system PR-URL: #3981 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
The modification time of a file is assumed to happen at the exact time when it was requested. As the utime API specification delcares that the resolution of the result is 1 second, relax the constrain to 1 second helps the test case to be robust and consistent under different load conditions in the system PR-URL: #3981 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
The modification time of a file is assumed to happen at the exact time when it was requested. As the utime API specification delcares that the resolution of the result is 1 second, relax the constrain to 1 second helps the test case to be robust and consistent under different load conditions in the system PR-URL: nodejs#3981 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
The test case in one of its tests, is trying to change the modification time of a file, and validate that the modification applied (through stat call) is indeed same as what was requested, at an accuracy level of seconds. The output indicates that this validation fails a few times when checked for 10000 times back-to-back.
utime manual says "The utime() system call allows specification of timestamps with a resolution of 1 second." My interpretation of this is that one should expect a deviation of at most one second for the actual modification time, from the requested time. This is reflected in the output of failed cases as well, as every pairs have exactly a difference of one.
However, the test case seems to assume that the actual and request time should match at the seconds level. Excepts from test case:
// check up to single-second precision
// sub-second precision is OS and fs dependant
return Math.floor(mtime) == Math.floor(real_mtime);
While this works for small workloads (less file system activities), when the stress on fs APIs increases (for example, if I increase the depth level of runTest callbacks) then the failure rate increases, and starts affecting Linux as well. The small test case above is in fact a stressed version of the original test case.
with the proposed change, the test passes consistently.