镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Commit 8b7ce8b

Browse files
Trottevanlucas
authored andcommitted
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 <cjihrig@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
1 parent 5ab172e commit 8b7ce8b

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
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)