Browse Source

test: fix flaky fs-watch tests

`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: https://github.com/nodejs/node/issues/8045
PR-URL: https://github.com/nodejs/node/pull/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>
v7.x
Santiago Gimeno 9 years ago
committed by James M Snell
parent
commit
5f617c5f9e
  1. 8
      test/parallel/test-fs-watch-recursive.js
  2. 9
      test/sequential/test-fs-watch.js

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

@ -13,14 +13,12 @@ const fs = require('fs');
const testDir = common.tmpDir; const testDir = common.tmpDir;
const filenameOne = 'watch.txt'; 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(); 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}); const watcher = fs.watch(testDir, {recursive: true});

9
test/sequential/test-fs-watch.js

@ -21,11 +21,6 @@ var filenameTwo = 'hasOwnProperty';
var filepathTwo = filenameTwo; var filepathTwo = filenameTwo;
var filepathTwoAbs = path.join(testDir, 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() { process.on('exit', function() {
assert.ok(watchSeenOne > 0); assert.ok(watchSeenOne > 0);
assert.ok(watchSeenTwo > 0); assert.ok(watchSeenTwo > 0);
@ -78,7 +73,9 @@ setImmediate(function() {
fs.writeFileSync(filepathTwoAbs, 'pardner'); 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( assert.doesNotThrow(
function() { function() {

Loading…
Cancel
Save