Skip to content

Commit

Permalink
test: fix flaky fs-watch tests
Browse files Browse the repository at this point in the history
`test-fs-watch-recursive` and `test-fs-watch` were both watching the
same folder: `tmp/testsubdir` so running them sequentially on `OS X`
could make `test-fs-watch` to fail due to events generated in the other
test. Make them watch a random directory to fix the issue.

Fixes: #8045
PR-URL: #8115
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
santigimeno authored and evanlucas committed Aug 24, 2016
1 parent 82329b6 commit 4f09886
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
8 changes: 3 additions & 5 deletions test/parallel/test-fs-watch-recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ const fs = require('fs');

const testDir = common.tmpDir;
const filenameOne = 'watch.txt';
const testsubdirName = 'testsubdir';
const testsubdir = path.join(testDir, testsubdirName);
const relativePathOne = path.join('testsubdir', filenameOne);
const filepathOne = path.join(testsubdir, filenameOne);

common.refreshTmpDir();

fs.mkdirSync(testsubdir, 0o700);
const testsubdir = fs.mkdtempSync(testDir + path.sep);
const relativePathOne = path.join(path.basename(testsubdir), filenameOne);
const filepathOne = path.join(testsubdir, filenameOne);

const watcher = fs.watch(testDir, {recursive: true});

Expand Down
9 changes: 3 additions & 6 deletions test/sequential/test-fs-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ var filenameTwo = 'hasOwnProperty';
var filepathTwo = filenameTwo;
var filepathTwoAbs = path.join(testDir, filenameTwo);

var filenameThree = 'newfile.txt';
var testsubdir = path.join(testDir, 'testsubdir');
var filepathThree = path.join(testsubdir, filenameThree);


process.on('exit', function() {
assert.ok(watchSeenOne > 0);
assert.ok(watchSeenTwo > 0);
Expand Down Expand Up @@ -78,7 +73,9 @@ setImmediate(function() {
fs.writeFileSync(filepathTwoAbs, 'pardner');
});

fs.mkdirSync(testsubdir, 0o700);
const filenameThree = 'newfile.txt';
const testsubdir = fs.mkdtempSync(testDir + path.sep);
const filepathThree = path.join(testsubdir, filenameThree);

assert.doesNotThrow(
function() {
Expand Down

0 comments on commit 4f09886

Please sign in to comment.