Skip to content

Commit 2119c76

Browse files
Trottrvagg
authored andcommitted
test: refactor test-fs-watch
* 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]>
1 parent e487b72 commit 2119c76

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

test/sequential/test-fs-watch.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ assert.doesNotThrow(
5151
}
5252
);
5353

54-
setTimeout(function() {
54+
setImmediate(function() {
5555
fs.writeFileSync(filepathOne, 'world');
56-
}, 20);
56+
});
5757

5858

5959
process.chdir(testDir);
@@ -74,17 +74,16 @@ assert.doesNotThrow(
7474
}
7575
);
7676

77-
setTimeout(function() {
77+
setImmediate(function() {
7878
fs.writeFileSync(filepathTwoAbs, 'pardner');
79-
}, 20);
79+
});
8080

81-
try { fs.unlinkSync(filepathThree); } catch (e) {}
82-
try { fs.mkdirSync(testsubdir, 0o700); } catch (e) {}
81+
fs.mkdirSync(testsubdir, 0o700);
8382

8483
assert.doesNotThrow(
8584
function() {
8685
var watcher = fs.watch(testsubdir, function(event, filename) {
87-
var renameEv = process.platform === 'sunos' ? 'change' : 'rename';
86+
var renameEv = common.isSunOS ? 'change' : 'rename';
8887
assert.equal(renameEv, event);
8988
if (expectFilePath) {
9089
assert.equal('newfile.txt', filename);
@@ -97,10 +96,10 @@ assert.doesNotThrow(
9796
}
9897
);
9998

100-
setTimeout(function() {
99+
setImmediate(function() {
101100
var fd = fs.openSync(filepathThree, 'w');
102101
fs.closeSync(fd);
103-
}, 20);
102+
});
104103

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

0 commit comments

Comments
 (0)