Skip to content
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

lib,src: make StatWatcher a HandleWrap #21244

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! test: improve statwatcher async_hooks test
  • Loading branch information
addaleax committed Jun 10, 2018
commit adfb579ec3d8cb480fd6f0d3a275f474bed13d27
25 changes: 15 additions & 10 deletions test/async-hooks/test-statwatcher.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
'use strict';

const common = require('../common');
const commonPath = require.resolve('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');
const fs = require('fs');
const path = require('path');

if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs');

tmpdir.refresh();

const file1 = path.join(tmpdir.path, 'file1');
const file2 = path.join(tmpdir.path, 'file2');
fs.writeFileSync(file1, 'foo');
fs.writeFileSync(file2, 'bar');

const hooks = initHooks();
hooks.enable();

function onchange() {}
// install first file watcher
const w1 = fs.watchFile(__filename, { interval: 10 }, onchange);
const w1 = fs.watchFile(file1, { interval: 10 }, onchange);

let as = hooks.activitiesOfTypes('STATWATCHER');
assert.strictEqual(as.length, 1);
Expand All @@ -28,7 +36,7 @@ checkInvocations(statwatcher1, { init: 1 },
'watcher1: when started to watch file');

// install second file watcher
const w2 = fs.watchFile(commonPath, { interval: 10 }, onchange);
const w2 = fs.watchFile(file2, { interval: 10 }, onchange);
as = hooks.activitiesOfTypes('STATWATCHER');
assert.strictEqual(as.length, 2);

Expand All @@ -41,9 +49,7 @@ checkInvocations(statwatcher1, { init: 1 },
checkInvocations(statwatcher2, { init: 1 },
'watcher2: when started to watch second file');

// Touch the first file by modifying its access time.
const origStat = fs.statSync(__filename);
fs.utimesSync(__filename, Date.now() + 10, origStat.mtime);
fs.writeFileSync(file1, 'foo++');
w1.once('change', common.mustCall(() => {
setImmediate(() => {
checkInvocations(statwatcher1, { init: 1, before: 1, after: 1 },
Expand All @@ -52,16 +58,15 @@ w1.once('change', common.mustCall(() => {
'watcher2: when unwatched first file');

// Touch the second file by modifying its access time.
const origStat = fs.statSync(commonPath);
fs.utimesSync(commonPath, Date.now() + 10, origStat.mtime);
fs.writeFileSync(file2, 'bar++');
w2.once('change', common.mustCall(() => {
setImmediate(() => {
checkInvocations(statwatcher1, { init: 1, before: 1, after: 1 },
'watcher1: when unwatched second file');
checkInvocations(statwatcher2, { init: 1, before: 1, after: 1 },
'watcher2: when unwatched second file');
w1.stop();
w2.stop();
fs.unwatchFile(file1);
fs.unwatchFile(file2);
});
}));
});
Expand Down