-
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 flaky test-fs-watchfile on macOS #13252
Conversation
On macOS, a watcher created with fs.watch() does not necessarily start receiving events immediately. So it can miss a change by fs.writefile() if it comes very soon after the watcher is created. Fix test flakiness caused by this by using `setInterval()` to repeat the write action. Fixes: nodejs#13248
Stress tests are being run with Stress test this PR (should succeed): https://ci.nodejs.org/job/node-stress-single-test/nodes=osx1010/1238/console Stress test master (should fail): https://ci.nodejs.org/job/node-stress-single-test/nodes=osx1010/1239/console (404 right now, but will appear when a host becomes available to run the test) |
Stress tests came back as expected: master with failures, this PR all green. |
fs.writeFile(`${dir}/foo.txt`, 'foo', common.mustCall(function(err) { | ||
if (err) assert.fail(err); | ||
})); | ||
}, 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.
[question] is 1
safe? does it not cause a busy-wait-ish situation?
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.
maybe change to try {fs.writeFileSych ...
?
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.
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.
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 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?
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.
LGTM
On macOS, a watcher created with fs.watch() does not necessarily start receiving events immediately. So it can miss a change by fs.writefile() if it comes very soon after the watcher is created. Fix test flakiness caused by this by using `setInterval()` to repeat the write action. PR-URL: nodejs#13252 Fixes: nodejs#13248 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]>
Landed in 3b12a8d |
On macOS, a watcher created with fs.watch() does not necessarily start receiving events immediately. So it can miss a change by fs.writefile() if it comes very soon after the watcher is created. Fix test flakiness caused by this by using `setInterval()` to repeat the write action. PR-URL: #13252 Fixes: #13248 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]>
This does not land cleanly in LTS. Please feel free to manually backport. Please also feel free to replace do-not-land if it is being backported |
On macOS, a watcher created with fs.watch() does not necessarily
start receiving events immediately. So it can miss a change by
fs.writefile() if it comes very soon after the watcher is created. Fix
test flakiness caused by this by using
setInterval()
to repeat thewrite action.
Fixes: #13248
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test fs