Skip to content

Commit

Permalink
test: make fs-watch-recursive less racy
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
indutny committed Dec 10, 2013
1 parent 259d449 commit 78cd453
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions test/simple/test-fs-watch-recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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();
Expand Down

0 comments on commit 78cd453

Please sign in to comment.