-
Notifications
You must be signed in to change notification settings - Fork 29.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: refactor test-fs-watchfile.js #2393
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ const common = require('../common'); | |
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('assert'); | ||
const fixtures = path.join(__dirname, '..', 'fixtures'); | ||
|
||
// Basic usage tests. | ||
assert.throws(function() { | ||
|
@@ -19,7 +18,7 @@ assert.throws(function() { | |
fs.watchFile(new Object(), function() {}); | ||
}, /Path must be a string/); | ||
|
||
const enoentFile = path.join(fixtures, 'non-existent-file'); | ||
const enoentFile = path.join(common.tmpDir, 'non-existent-file'); | ||
const expectedStatObject = new fs.Stats( | ||
0, // dev | ||
0, // mode | ||
|
@@ -37,24 +36,13 @@ const expectedStatObject = new fs.Stats( | |
Date.UTC(1970, 0, 1, 0, 0, 0) // birthtime | ||
); | ||
|
||
function removeTestFile() { | ||
try { | ||
fs.unlinkSync(enoentFile); | ||
} catch (ex) { | ||
if (ex.code !== 'ENOENT') { | ||
throw ex; | ||
} | ||
} | ||
} | ||
|
||
// Make sure that the file does not exist, when the test starts | ||
removeTestFile(); | ||
common.refreshTmpDir(); | ||
|
||
// If the file initially didn't exist, and gets created at a later point of | ||
// time, the callback should be invoked again with proper values in stat object | ||
var fileExists = false; | ||
|
||
fs.watchFile(enoentFile, common.mustCall(function(curr, prev) { | ||
fs.watchFile(enoentFile, {interval: 0}, common.mustCall(function(curr, prev) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wondering, how does an interval of zero work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figured that would poll every time the event loop finished. Ultimately, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose the whole "what happens if you set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically correct, although libuv may change it someday to mean the lowest supported or most optimal poll interval. From the manual:
|
||
if (!fileExists) { | ||
// If the file does not exist, all the fields should be zero and the date | ||
// fields should be UNIX EPOCH time | ||
|
@@ -71,8 +59,7 @@ fs.watchFile(enoentFile, common.mustCall(function(curr, prev) { | |
// As the file just got created, previous ino value should be lesser than | ||
// or equal to zero (non-existent file). | ||
assert(prev.ino <= 0); | ||
// Stop watching the file and delete it | ||
// Stop watching the file | ||
fs.unwatchFile(enoentFile); | ||
removeTestFile(); | ||
} | ||
}, 2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't
common.refreshTmpDir()
be called before usingcommon.tmpDir
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refreshTmpDir()
should be called before creating files incommon.tmpDir
but there's no reason why the path to the file can't be created and saved first as it is here.