From b0476c55905ed177f447739c4710c0505fe630eb Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 26 Oct 2016 15:44:10 -0700 Subject: [PATCH] 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 Reviewed-By: Santiago Gimeno --- test/parallel/test-fs-watch-recursive.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-fs-watch-recursive.js b/test/parallel/test-fs-watch-recursive.js index 1fca541505b9c1..8d25d767080623 100644 --- a/test/parallel/test-fs-watch-recursive.js +++ b/test/parallel/test-fs-watch-recursive.js @@ -32,14 +32,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'); }