Skip to content
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

Closed
wants to merge 1 commit into from
Closed

test: fix time resolution constrain #3981

wants to merge 1 commit into from

Conversation

gireeshpunathil
Copy link
Member

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.

@@ -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);
Copy link
Member

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

Copy link
Member

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?

@mscdex mscdex added fs Issues and PRs related to the fs subsystem / file system. test Issues and PRs related to the tests. labels Nov 23, 2015
@gireeshpunathil
Copy link
Member Author

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
@gireeshpunathil
Copy link
Member Author

Both are working, picked up @bnoordhuis' suggestion as it is more compact. Please review and do the needful. Thanks!

@bnoordhuis
Copy link
Member

@cjihrig
Copy link
Contributor

cjihrig commented Nov 24, 2015

I'm a little late, but LGTM, and appreciate the detailed write up.

@JungMinu
Copy link
Member

JungMinu commented Dec 5, 2015

LGTM

@bnoordhuis
Copy link
Member

@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/

@JungMinu
Copy link
Member

JungMinu commented Dec 5, 2015

@bnoordhuis sorry to bug you, I will handle it now

JungMinu pushed a commit that referenced this pull request Dec 5, 2015
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 <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
@JungMinu
Copy link
Member

JungMinu commented Dec 5, 2015

Thanks, Landed in cf65299

@JungMinu JungMinu closed this Dec 5, 2015
rvagg pushed a commit that referenced this pull request Dec 8, 2015
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 <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
@rvagg rvagg mentioned this pull request Dec 17, 2015
MylesBorins pushed a commit that referenced this pull request Dec 29, 2015
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 <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jan 19, 2016
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 <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Jan 19, 2016
scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
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 <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants