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 flaky test-fs-watchfile on macOS #13252

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
9 changes: 6 additions & 3 deletions test/parallel/test-fs-watchfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ if (common.isLinux || common.isOSX || common.isWindows || common.isAix) {
if (err) assert.fail(err);

fs.watch(dir, common.mustCall(function(eventType, filename) {
clearInterval(interval);
this._handle.close();
assert.strictEqual(filename, 'foo.txt');
}));

fs.writeFile(`${dir}/foo.txt`, 'foo', common.mustCall(function(err) {
if (err) assert.fail(err);
}));
const interval = setInterval(() => {
fs.writeFile(`${dir}/foo.txt`, 'foo', common.mustCall(function(err) {
if (err) assert.fail(err);
}));
}, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

[question] is 1 safe? does it not cause a busy-wait-ish situation?

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe change to try {fs.writeFileSych ...?

Copy link
Member Author

Choose a reason for hiding this comment

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

is 1 safe?

It won't block the event loop or anything like that, if that's what you mean. The way intervals work, the next one only gets added to the queue after the first one finishes, and gets added to execute in the next tick of the event loop at the earliest.

Copy link
Contributor

Choose a reason for hiding this comment

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

I figured it will not block the loop, but maybe stress the I/O. Although obviously the process shouldn't be doing anything else at this point.
I agree it's a least arbitrary value you could put here, so guess it could be read a sort of nextTickInterval idiom?

}));
}