Skip to content

Commit

Permalink
test: fix flaky test-fs-watch-recursive on OS X
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Trott authored and Myles Borins committed Nov 22, 2016
1 parent 4ef7f00 commit 8b2b08a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions test/parallel/test-fs-watch-recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ watcher.on('change', function(event, filename) {
if (filename !== relativePathOne)
return;

if (common.isOSX) {
clearInterval(interval);
}
watcher.close();
watcherClosed = true;
});

if (process.platform === 'darwin') {
setTimeout(function() {
if (common.isOSX) {
var interval = setInterval(function() {
fs.writeFileSync(filepathOne, 'world');
}, 100);
}, 10);
} else {
fs.writeFileSync(filepathOne, 'world');
}
Expand Down

0 comments on commit 8b2b08a

Please sign in to comment.