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,fs: test fs.watch for filename #13411

Merged
merged 1 commit into from
Jun 7, 2017
Merged

Conversation

refack
Copy link
Contributor

@refack refack commented Jun 2, 2017

Ref: #13385
Ref: #13248
Ref: #13377

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

test,fs

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Jun 2, 2017
@refack refack added aix Issues and PRs related to the AIX platform. fs Issues and PRs related to the fs subsystem / file system. labels Jun 2, 2017
@refack
Copy link
Contributor Author

refack commented Jun 2, 2017

this._handle.close();
assert.strictEqual(filename, 'foo.txt');
}));
function WatchTestCase(is, dirName, fileName, field) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is is a very nondescriptive name… I’d probably use the reverse and call it skip.

Copy link
Contributor Author

@refack refack Jun 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldSkip Ok? I like predicates with predicate names.

Object.defineProperties(this, {
dirPath: { get: () => `${common.tmpDir}/${this.dirName}` },
filePath: { get: () => `${this.dirPath}/${this.fileName}` }
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not turn this into an ES6 class and use fancy get dirPath() { … } syntax? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

silly conservatism.
Will refactor.

if (!testCase.is) continue;
fs.mkdirSync(testCase.dirPath);
// long content so it's actually flushed.
const content1 = Date.now() + testCase.fileName.repeat(Math.random() * 1e5);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why Math.random()? I am a bit afraid that this reduces test reproducibility. If you use any random values in a test, please log them to stderr, and if there is an actual reason for Math.random() please add a comment that describes it – but I’d guess just using .repease(10000) would to the job just fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remnant from earlier iteration.
Not needed now.

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code changes look good, but it would be good if you could explain why this is being moved to sequential.

Also, I don’t really get why the setInterval() was there before… but well, if it passes CI, fine by me. :)

}
get dirPath() { return `${common.tmpDir}/${this.dirName}`; }
get filePath() { return `${this.dirPath}/${this.fileName}`; }
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaah, much better. :)

@Trott
Copy link
Member

Trott commented Jun 2, 2017

I don't think this needs to be moved to sequential. When I stress tested the original in sequential, it still failed on AIX. So I don't think it's necessarily load-dependent. I think just sometimes AIX is unreliable with the directory watchers and it's a known limitation of the OS at this time.

A comment for the setInterval() is probably a good idea. The deal there is that macOS in particular (and maybe other operating systems?) seem to (sometimes?) return an unarmed watcher and so we use the interval to write and write and write again until the watcher notices. It might miss the first one or two. It's a race condition.

@refack
Copy link
Contributor Author

refack commented Jun 2, 2017

Stress: https://ci.nodejs.org/job/node-stress-single-test/nodes=aix61-ppc64/1267/

The code changes look good, but it would be good if you could explain why this is being moved to sequential.

Also, I don’t really get why the setInterval() was there before… but well, if it passes CI, fine by me. :)

Move to sequential not necessary. Removed.

The backstory is in the refs. tl;dr

  1. in c470f04 we started watching directories to verify we get filename on change
  2. test was flaky on macOS - 3b12a8d (setInterval) solved that
  3. now it's only flaky on AIX
  4. this test is to test if watching a file works even on AIX

@refack refack added the wip Issues and PRs that are still a work in progress. label Jun 2, 2017
@Trott
Copy link
Member

Trott commented Jun 2, 2017

Oh, also a comment explaining why AIX is included in one but left out of the other would be helpful. Can be as simple as:

// Node.js on AIX can watch reliably on a file but not (at the current time) on a directory.

If you want to be thorough, maybe include a link to one of @gireeshpunathil's comments explaining.

@Trott
Copy link
Member

Trott commented Jun 2, 2017

Thanks for making this all more thorough.

I wonder if the fs.watch() stuff should all be moved to its own file at this point and leave the rest of the test for fs.watchFile() as the name of the test implies.

@refack
Copy link
Contributor Author

refack commented Jun 2, 2017

So apparently this is still in progress. My assumption that a big file will replace the need for setInterval and watching a file works on AIX, were not true. So testing variations.

Oh, also a comment explaining why AIX is included in one but left out of the other would be helpful. Can be as simple as:

// Node.js on AIX can watch reliably on a file but not (at the current time) on a directory.
If you want to be thorough, maybe include a link to one of @gireeshpunathil's comments explaining.

I assumed this would land after #13385

I wonder if the fs.watch() stuff should all be moved to its own file at this point and leave the rest of the test for fs.watchFile() as the name of the test implies.

There is a test/sequential/test-fs-watch.js. When this works and stable, I'll move it.

@refack
Copy link
Contributor Author

refack commented Jun 2, 2017

@refack
Copy link
Contributor Author

refack commented Jun 2, 2017

@refack
Copy link
Contributor Author

refack commented Jun 2, 2017

@refack
Copy link
Contributor Author

refack commented Jun 2, 2017

@refack
Copy link
Contributor Author

refack commented Jun 3, 2017

AIX remove from "watch dir" case
https://ci.nodejs.org/job/node-stress-single-test/1273/

@refack
Copy link
Contributor Author

refack commented Jun 4, 2017

@refack
Copy link
Contributor Author

refack commented Jun 4, 2017

@refack
Copy link
Contributor Author

refack commented Jun 5, 2017

new output on macOS:

485	parallel/test-fs-watchfile	
duration_ms	0.294
severity	fail
stack	
watching /Users/iojs/node-tmp/tmp.0/watch1/foo
watching /Users/iojs/node-tmp/tmp.0/watch2
changing /Users/iojs/node-tmp/tmp.0/watch1/foo
changing /Users/iojs/node-tmp/tmp.0/watch2/bar
assert.js:60
  throw new errors.AssertionError({
  ^

AssertionError [ERR_ASSERTION]: 'rename' === 'change'
    at FSWatcher.<anonymous> (/Users/iojs/build/workspace/node-test-commit-osx/nodes/osx1010/test/parallel/test-fs-watchfile.js:116:12)
    at FSWatcher.<anonymous> (/Users/iojs/build/workspace/node-test-commit-osx/nodes/osx1010/test/common/index.js:517:15)
    at emitTwo (events.js:125:13)
    at FSWatcher.emit (events.js:213:7)
    at FSEvent.FSWatcher._handle.onchange (fs.js:1362:12)

@@ -93,9 +93,10 @@ const cases = [
];
for (const testCase of cases) {
if (testCase.shouldSkip) continue;
console.log(`watching ${testCase[testCase.field]}`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the console.log() is not part of the test, please omit it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do when investigation finishes.

@refack
Copy link
Contributor Author

refack commented Jun 5, 2017

@refack refack force-pushed the fix-13111-13248 branch 2 times, most recently from 8845436 to e4d8546 Compare June 5, 2017 22:13
@refack
Copy link
Contributor Author

refack commented Jun 5, 2017

@refack refack changed the title test,fs: test watch of file and directory test,fs: test fs.watch for filename Jun 5, 2017
@refack refack self-assigned this Jun 5, 2017
@refack refack added the macos Issues and PRs related to the macOS platform / OSX. label Jun 5, 2017
@refack
Copy link
Contributor Author

refack commented Jun 6, 2017

@refack
Copy link
Contributor Author

refack commented Jun 6, 2017

@refack
Copy link
Contributor Author

refack commented Jun 6, 2017

New failures on AIX, so testing with no rebase: https://ci.nodejs.org/job/node-test-commit-aix/6394/

@gireeshpunathil
Copy link
Member

@refack, I guess the new failures you saw for AIX is in this CI run? if so I believe it is an infra issue, and has resolved by its own in your latest run. Please confirm my understanding, so that there is nothing else to look into from AIX side. Thanks!

@refack
Copy link
Contributor Author

refack commented Jun 7, 2017

@refack, I guess the new failures you saw for AIX is in this CI run? if so I believe it is an infra issue, and has resolved by its own in your latest run. Please confirm my understanding, so that there is nothing else to look into from AIX side. Thanks!

Yes, https://ci.nodejs.org/job/node-test-commit-aix/6384/nodes=aix61-ppc64/tapResults/
I'm not sure it's infra, so I have this open in one of my tabs for follow up, but...
image

PR-URL: nodejs#13411
Refs: nodejs#13385
Refs: nodejs#13248
Refs: nodejs#13377
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
@refack
Copy link
Contributor Author

refack commented Jun 7, 2017

Landed in c05561e

@refack refack merged commit c05561e into nodejs:master Jun 7, 2017
@refack
Copy link
Contributor Author

refack commented Jun 7, 2017

Extra post-land sanity of master: https://ci.nodejs.org/job/node-test-commit-linuxone/6444/

jasnell pushed a commit that referenced this pull request Jun 7, 2017
PR-URL: #13411
Refs: #13385
Refs: #13248
Refs: #13377
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
@refack refack deleted the fix-13111-13248 branch June 10, 2017 21:14
@refack refack removed their assignment Jun 12, 2017
@gibfahn gibfahn mentioned this pull request Jun 15, 2017
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aix Issues and PRs related to the AIX platform. fs Issues and PRs related to the fs subsystem / file system. macos Issues and PRs related to the macOS platform / OSX. test Issues and PRs related to the tests. wip Issues and PRs that are still a work in progress.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants