From 424d91aacbee399e520c533ac4ea540a69a5f356 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 17 Jun 2019 15:01:02 -0700 Subject: [PATCH] test: add logging to statwatcher test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs: https://github.com/nodejs/node/issues/21425#issuecomment-502667718 PR-URL: https://github.com/nodejs/node/pull/28270 Reviewed-By: Ruben Bridgewater Reviewed-By: Refael Ackermann (רפאל פלחי) Reviewed-By: Anna Henningsen --- test/async-hooks/test-statwatcher.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/test/async-hooks/test-statwatcher.js b/test/async-hooks/test-statwatcher.js index 1349fa87e6f511..48d7b0b22eedff 100644 --- a/test/async-hooks/test-statwatcher.js +++ b/test/async-hooks/test-statwatcher.js @@ -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');