Skip to content

Commit

Permalink
test: add logging to statwatcher test
Browse files Browse the repository at this point in the history
Refs: #21425 (comment)

PR-URL: #28270
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Refael Ackermann (רפאל פלחי) <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
Trott authored and targos committed Jul 2, 2019
1 parent 359e20f commit 424d91a
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions test/async-hooks/test-statwatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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');
Expand All @@ -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');
Expand Down

0 comments on commit 424d91a

Please sign in to comment.