Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! test: improve statwatcher async_hooks test
  • Loading branch information
addaleax committed Jun 10, 2018
commit c88680b5f35286ad4b4a75f5547cfdfd8947c433
5 changes: 2 additions & 3 deletions test/async-hooks/test-statwatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,15 @@ checkInvocations(statwatcher1, { init: 1 },
checkInvocations(statwatcher2, { init: 1 },
'watcher2: when started to watch second file');

fs.writeFileSync(file1, 'foo++');
setTimeout(() => fs.writeFileSync(file1, 'foo++'), 10);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could this be setImmediate or is that unreliable?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we can't use that, shouldn't we be using the platform timeout modifier?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So… the reason for this is that the stat watcher itself internally itself uses file system requests + timeouts. In order to witness a change, the write needs to hit a spot after the initial internal stat request has completed, but that’s timing that we can’t really track.

I’ve updated to use common.platformTimeout(100).

w1.once('change', common.mustCall(() => {
setImmediate(() => {
checkInvocations(statwatcher1, { init: 1, before: 1, after: 1 },
'watcher1: when unwatched first file');
checkInvocations(statwatcher2, { init: 1 },
'watcher2: when unwatched first file');

// Touch the second file by modifying its access time.
fs.writeFileSync(file2, 'bar++');
setTimeout(() => fs.writeFileSync(file2, 'bar++'), 10);
w2.once('change', common.mustCall(() => {
setImmediate(() => {
checkInvocations(statwatcher1, { init: 1, before: 1, after: 1 },
Expand Down