Browse Source

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: https://github.com/nodejs/node/issues/8511
PR-URL: https://github.com/nodejs/node/pull/9303
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
v6.x
Rich Trott 8 years ago
committed by Myles Borins
parent
commit
8b2b08a636
  1. 9
      test/parallel/test-fs-watch-recursive.js

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

@ -30,14 +30,17 @@ watcher.on('change', function(event, filename) {
if (filename !== relativePathOne) if (filename !== relativePathOne)
return; return;
if (common.isOSX) {
clearInterval(interval);
}
watcher.close(); watcher.close();
watcherClosed = true; watcherClosed = true;
}); });
if (process.platform === 'darwin') { if (common.isOSX) {
setTimeout(function() { var interval = setInterval(function() {
fs.writeFileSync(filepathOne, 'world'); fs.writeFileSync(filepathOne, 'world');
}, 100); }, 10);
} else { } else {
fs.writeFileSync(filepathOne, 'world'); fs.writeFileSync(filepathOne, 'world');
} }

Loading…
Cancel
Save