Skip to content

Commit 25a05e5

Browse files
Trottjasnell
authored andcommitted
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 <[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]>
1 parent ec357bf commit 25a05e5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

test/parallel/test-fs-watchfile.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,15 @@ if (common.isLinux || common.isOSX || common.isWindows || common.isAix) {
7272
if (err) assert.fail(err);
7373

7474
fs.watch(dir, common.mustCall(function(eventType, filename) {
75+
clearInterval(interval);
7576
this._handle.close();
7677
assert.strictEqual(filename, 'foo.txt');
7778
}));
7879

79-
fs.writeFile(`${dir}/foo.txt`, 'foo', common.mustCall(function(err) {
80-
if (err) assert.fail(err);
81-
}));
80+
const interval = setInterval(() => {
81+
fs.writeFile(`${dir}/foo.txt`, 'foo', common.mustCall(function(err) {
82+
if (err) assert.fail(err);
83+
}));
84+
}, 1);
8285
}));
8386
}

0 commit comments

Comments
 (0)