summaryrefslogtreecommitdiff
path: root/test/pummel/test-fs-watch-file-slow.js
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2012-06-21 02:25:56 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2012-06-21 02:50:13 +0200
commitd98a8578d62cd1b35574269dc028a0c8c34ef25b (patch)
tree3c8fa30ca9c196a0af38d3885efb7d0d2264b2aa /test/pummel/test-fs-watch-file-slow.js
parent09150b0616906a9ce1533796ec49c4bee8841e48 (diff)
downloadandroid-node-v8-d98a8578d62cd1b35574269dc028a0c8c34ef25b.tar.gz
android-node-v8-d98a8578d62cd1b35574269dc028a0c8c34ef25b.tar.bz2
android-node-v8-d98a8578d62cd1b35574269dc028a0c8c34ef25b.zip
test: add another fs.watchFile() test
Diffstat (limited to 'test/pummel/test-fs-watch-file-slow.js')
-rw-r--r--test/pummel/test-fs-watch-file-slow.js73
1 files changed, 73 insertions, 0 deletions
diff --git a/test/pummel/test-fs-watch-file-slow.js b/test/pummel/test-fs-watch-file-slow.js
new file mode 100644
index 0000000000..4124e0b272
--- /dev/null
+++ b/test/pummel/test-fs-watch-file-slow.js
@@ -0,0 +1,73 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var common = require('../common');
+var assert = require('assert');
+var path = require('path');
+var fs = require('fs');
+
+var FILENAME = path.join(common.tmpDir, 'watch-me');
+var TIMEOUT = 1300;
+
+var nevents = 0;
+
+try {
+ fs.unlinkSync(FILENAME);
+}
+catch (e) {
+ // swallow
+}
+
+fs.watchFile(FILENAME, {interval:TIMEOUT - 250}, function(curr, prev) {
+ console.log([curr, prev]);
+ switch (++nevents) {
+ case 1:
+ case 2:
+ assert.equal(fs.existsSync(FILENAME), true);
+ break;
+ case 3:
+ assert.equal(fs.existsSync(FILENAME), false);
+ fs.unwatchFile(FILENAME);
+ break;
+ default:
+ assert(0);
+ }
+});
+
+process.on('exit', function() {
+ assert.equal(nevents, 3);
+});
+
+setTimeout(createFile, TIMEOUT);
+
+function createFile() {
+ fs.writeFileSync(FILENAME, "test");
+ setTimeout(touchFile, TIMEOUT);
+}
+
+function touchFile() {
+ fs.writeFileSync(FILENAME, "test");
+ setTimeout(removeFile, TIMEOUT);
+}
+
+function removeFile() {
+ fs.unlinkSync(FILENAME);
+}