Skip to content

Commit b0476c5

Browse files
TrottMyles Borins
authored and
Myles Borins
committed
test: fix flaky test-fs-watch-recursive on OS X
The test was sometimes timing out due to a race condition. In OS X, events for `fs.watch()` might only start showing up after a delay. This is a limitation of the operating system. To work around that, there was a timer in the test that delayed the writing of the file by 100ms. However, sometimes that was not enough, and so the event never fired, and the test timed out. Change the timer to an interval so that it fires repeatedly until it is picked up. This change only affects OS X. Fixes: #8511 PR-URL: #9303 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]>
1 parent bcd156f commit b0476c5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

test/parallel/test-fs-watch-recursive.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,17 @@ watcher.on('change', function(event, filename) {
3232
if (filename !== relativePathOne)
3333
return;
3434

35+
if (common.isOSX) {
36+
clearInterval(interval);
37+
}
3538
watcher.close();
3639
watcherClosed = true;
3740
});
3841

39-
if (process.platform === 'darwin') {
40-
setTimeout(function() {
42+
if (common.isOSX) {
43+
var interval = setInterval(function() {
4144
fs.writeFileSync(filepathOne, 'world');
42-
}, 100);
45+
}, 10);
4346
} else {
4447
fs.writeFileSync(filepathOne, 'world');
4548
}

0 commit comments

Comments
 (0)