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: https://github.com/nodejs/node/pull/13252 Fixes: https://github.com/nodejs/node/issues/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>
This commit is contained in:
parent
64ded9f9bc
commit
3b12a8d6e7
@ -72,12 +72,15 @@ if (common.isLinux || common.isOSX || common.isWindows || common.isAix) {
|
|||||||
if (err) assert.fail(err);
|
if (err) assert.fail(err);
|
||||||
|
|
||||||
fs.watch(dir, common.mustCall(function(eventType, filename) {
|
fs.watch(dir, common.mustCall(function(eventType, filename) {
|
||||||
|
clearInterval(interval);
|
||||||
this._handle.close();
|
this._handle.close();
|
||||||
assert.strictEqual(filename, 'foo.txt');
|
assert.strictEqual(filename, 'foo.txt');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const interval = setInterval(() => {
|
||||||
fs.writeFile(`${dir}/foo.txt`, 'foo', common.mustCall(function(err) {
|
fs.writeFile(`${dir}/foo.txt`, 'foo', common.mustCall(function(err) {
|
||||||
if (err) assert.fail(err);
|
if (err) assert.fail(err);
|
||||||
}));
|
}));
|
||||||
|
}, 1);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user