Skip to content

Commit 4f09886

Browse files
santigimenoevanlucas
authored andcommitted
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: #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>
1 parent 82329b6 commit 4f09886

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ const fs = require('fs');
1313

1414
const testDir = common.tmpDir;
1515
const filenameOne = 'watch.txt';
16-
const testsubdirName = 'testsubdir';
17-
const testsubdir = path.join(testDir, testsubdirName);
18-
const relativePathOne = path.join('testsubdir', filenameOne);
19-
const filepathOne = path.join(testsubdir, filenameOne);
2016

2117
common.refreshTmpDir();
2218

23-
fs.mkdirSync(testsubdir, 0o700);
19+
const testsubdir = fs.mkdtempSync(testDir + path.sep);
20+
const relativePathOne = path.join(path.basename(testsubdir), filenameOne);
21+
const filepathOne = path.join(testsubdir, filenameOne);
2422

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

test/sequential/test-fs-watch.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ var filenameTwo = 'hasOwnProperty';
2121
var filepathTwo = filenameTwo;
2222
var filepathTwoAbs = path.join(testDir, filenameTwo);
2323

24-
var filenameThree = 'newfile.txt';
25-
var testsubdir = path.join(testDir, 'testsubdir');
26-
var filepathThree = path.join(testsubdir, filenameThree);
27-
28-
2924
process.on('exit', function() {
3025
assert.ok(watchSeenOne > 0);
3126
assert.ok(watchSeenTwo > 0);
@@ -78,7 +73,9 @@ setImmediate(function() {
7873
fs.writeFileSync(filepathTwoAbs, 'pardner');
7974
});
8075

81-
fs.mkdirSync(testsubdir, 0o700);
76+
const filenameThree = 'newfile.txt';
77+
const testsubdir = fs.mkdtempSync(testDir + path.sep);
78+
const filepathThree = path.join(testsubdir, filenameThree);
8279

8380
assert.doesNotThrow(
8481
function() {

0 commit comments

Comments
 (0)