From 78cd4533d9f14cd83e9cd7817dffdd4e6af600c5 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 21 Nov 2013 21:06:29 +0400 Subject: [PATCH] test: make fs-watch-recursive less racy FSEventStream may emit events that happened right before it has started. Ignore changes emitted for the directory itself, since they may come from the stale events. --- test/simple/test-fs-watch-recursive.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/simple/test-fs-watch-recursive.js b/test/simple/test-fs-watch-recursive.js index a5ebad605f..e421ab0222 100644 --- a/test/simple/test-fs-watch-recursive.js +++ b/test/simple/test-fs-watch-recursive.js @@ -30,7 +30,8 @@ if (process.platform === 'darwin') { var testDir = common.tmpDir; var filenameOne = 'watch.txt'; - var testsubdir = path.join(testDir, 'testsubdir'); + var testsubdirName = 'testsubdir'; + var testsubdir = path.join(testDir, testsubdirName); var relativePathOne = path.join('testsubdir', filenameOne); var filepathOne = path.join(testsubdir, filenameOne); @@ -44,12 +45,16 @@ if (process.platform === 'darwin') { }; try { fs.mkdirSync(testsubdir, 0700); } catch (e) {} - fs.writeFileSync(filepathOne, 'hello'); assert.doesNotThrow(function() { var watcher = fs.watch(testDir, {recursive: true}); watcher.on('change', function(event, filename) { assert.ok('change' === event || 'rename' === event); + + // Ignore stale events generated by mkdir + if (filename === testsubdirName) + return; + assert.equal(relativePathOne, filename); watcher.close();