diff options
author | Rich Trott <rtrott@gmail.com> | 2016-01-19 23:30:43 -0800 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2016-01-21 15:08:31 -0800 |
commit | d26b0143910250fffae4b97f8ea376ede1ef4093 (patch) | |
tree | 41be7f977a0d03aaa6874f7a50f9750d0efe6bbf | |
parent | 5ef9989bd6f980bccae8a186c93b974f51791a4d (diff) | |
download | node-new-d26b0143910250fffae4b97f8ea376ede1ef4093.tar.gz |
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: https://github.com/nodejs/node/pull/4776
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
-rw-r--r-- | test/sequential/test-fs-watch.js | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/test/sequential/test-fs-watch.js b/test/sequential/test-fs-watch.js index 10f4baf591..51d737ddbe 100644 --- a/test/sequential/test-fs-watch.js +++ b/test/sequential/test-fs-watch.js @@ -51,9 +51,9 @@ assert.doesNotThrow( } ); -setTimeout(function() { +setImmediate(function() { fs.writeFileSync(filepathOne, 'world'); -}, 20); +}); process.chdir(testDir); @@ -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); @@ -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 |