Skip to content

Commit 8b2b08a

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 4ef7f00 commit 8b2b08a

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
@@ -30,14 +30,17 @@ watcher.on('change', function(event, filename) {
3030
if (filename !== relativePathOne)
3131
return;
3232

33+
if (common.isOSX) {
34+
clearInterval(interval);
35+
}
3336
watcher.close();
3437
watcherClosed = true;
3538
});
3639

37-
if (process.platform === 'darwin') {
38-
setTimeout(function() {
40+
if (common.isOSX) {
41+
var interval = setInterval(function() {
3942
fs.writeFileSync(filepathOne, 'world');
40-
}, 100);
43+
}, 10);
4144
} else {
4245
fs.writeFileSync(filepathOne, 'world');
4346
}

0 commit comments

Comments
 (0)