Permalink
Browse files

test: fix flaky test-fs-watchfile on macOS

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 <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
Trott committed May 27, 2017
1 parent 64ded9f commit 3b12a8d6e7a053ba873de5a9b3c1d580ada294ac
Showing with 6 additions and 3 deletions.
  1. +6 −3 test/parallel/test-fs-watchfile.js
@@ -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);
}));
}

0 comments on commit 3b12a8d

Please sign in to comment.