test: add logging to statwatcher test

Refs: https://github.com/nodejs/node/issues/21425#issuecomment-502667718

PR-URL: https://github.com/nodejs/node/pull/28270
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Refael Ackermann (רפאל פלחי) <refack@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
pull/28270/head
Rich Trott 2019-06-17 15:01:02 -07:00
parent 1a4f27ae21
commit f28b1ed18f
1 changed files with 17 additions and 5 deletions

View File

@ -21,9 +21,13 @@ fs.writeFileSync(file2, 'bar');
const hooks = initHooks();
hooks.enable();
function onchange() {}
function onchange1(curr, prev) {
console.log('Watcher: w1');
console.log('current stat data:', curr);
console.log('previous stat data:', prev);
}
// Install first file watcher
const w1 = fs.watchFile(file1, { interval: 10 }, onchange);
const w1 = fs.watchFile(file1, { interval: 10 }, onchange1);
let as = hooks.activitiesOfTypes('STATWATCHER');
assert.strictEqual(as.length, 1);
@ -35,8 +39,14 @@ assert.strictEqual(statwatcher1.triggerAsyncId, 1);
checkInvocations(statwatcher1, { init: 1 },
'watcher1: when started to watch file');
function onchange2(curr, prev) {
console.log('Watcher: w2');
console.log('current stat data:', curr);
console.log('previous stat data:', prev);
}
// Install second file watcher
const w2 = fs.watchFile(file2, { interval: 10 }, onchange);
const w2 = fs.watchFile(file2, { interval: 10 }, onchange2);
as = hooks.activitiesOfTypes('STATWATCHER');
assert.strictEqual(as.length, 2);
@ -51,7 +61,8 @@ checkInvocations(statwatcher2, { init: 1 },
setTimeout(() => fs.writeFileSync(file1, 'foo++'),
common.platformTimeout(100));
w1.once('change', common.mustCall(() => {
w1.once('change', common.mustCall((curr, prev) => {
console.log('w1 change', curr, prev);
setImmediate(() => {
checkInvocations(statwatcher1, { init: 1, before: 1, after: 1 },
'watcher1: when unwatched first file');
@ -60,7 +71,8 @@ w1.once('change', common.mustCall(() => {
setTimeout(() => fs.writeFileSync(file2, 'bar++'),
common.platformTimeout(100));
w2.once('change', common.mustCall(() => {
w2.once('change', common.mustCall((curr, prev) => {
console.log('w2 change', curr, prev);
setImmediate(() => {
checkInvocations(statwatcher1, { init: 1, before: 1, after: 1 },
'watcher1: when unwatched second file');