Skip to content

Commit

Permalink
test: refactor test-fs-watch
Browse files Browse the repository at this point in the history
* Exchange 20 millisecond timers for setImmediate().

* Do not attempt to unlink path that will have been guaranteed to be
removed by `common.refreshTmpDir()`

* Do not swallow errors thrown by failed creation of needed test
subdirectory. If that happens, we want to know about it.

* Use `common.isSunOS` in one place where it is applicable

PR-URL: #4776
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
  • Loading branch information
Trott authored and rvagg committed Jan 25, 2016
1 parent e487b72 commit 2119c76
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions test/sequential/test-fs-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ assert.doesNotThrow(
}
);

setTimeout(function() {
setImmediate(function() {
fs.writeFileSync(filepathOne, 'world');
}, 20);
});


process.chdir(testDir);
Expand All @@ -74,17 +74,16 @@ assert.doesNotThrow(
}
);

setTimeout(function() {
setImmediate(function() {
fs.writeFileSync(filepathTwoAbs, 'pardner');
}, 20);
});

try { fs.unlinkSync(filepathThree); } catch (e) {}
try { fs.mkdirSync(testsubdir, 0o700); } catch (e) {}
fs.mkdirSync(testsubdir, 0o700);

assert.doesNotThrow(
function() {
var watcher = fs.watch(testsubdir, function(event, filename) {
var renameEv = process.platform === 'sunos' ? 'change' : 'rename';
var renameEv = common.isSunOS ? 'change' : 'rename';
assert.equal(renameEv, event);
if (expectFilePath) {
assert.equal('newfile.txt', filename);
Expand All @@ -97,10 +96,10 @@ assert.doesNotThrow(
}
);

setTimeout(function() {
setImmediate(function() {
var fd = fs.openSync(filepathThree, 'w');
fs.closeSync(fd);
}, 20);
});

// https://github.com/joyent/node/issues/2293 - non-persistent watcher should
// not block the event loop
Expand Down

0 comments on commit 2119c76

Please sign in to comment.