node/test/parallel/test-fs-watch-encoding.js
Gireesh Punathil 46edd940e8 fs: re-enable watch facility in AIX
On AIX, watch feature depends on AHAFS based Event infrastructure.
While in principle the watch use case is same across platforms, there
are subtle differences in the way AIX deals with this, with few
behavioral changes (external).

This commit addresses an assertion failure on folder watch, enabling the
AIX code for watch feature which was masked under a macro, open up
relevant test cases, skip tests which comes under the AIX limitation,
and make the document changes as appropriate.

Refs: https://github.com/nodejs/node/pull/11094
Refs: https://github.com/nodejs/node/issues/5085
PR-URL: https://github.com/nodejs/node/pull/10085
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-02-09 13:53:45 -05:00

85 lines
2.1 KiB
JavaScript

'use strict';
// This test is a bit more complicated than it ideally needs to be to work
// around issues on OS X and SmartOS.
//
// On OS X, watch events are subject to peculiar timing oddities such that an
// event might fire out of order. The synchronous refreshing of the tmp
// directory might trigger an event on the watchers that are instantiated after
// it!
//
// On SmartOS, the watch events fire but the filename is null.
const common = require('../common');
const fs = require('fs');
const path = require('path');
// fs-watch on folders have limited capability in AIX.
// The testcase makes use of folder watching, and causes
// hang. This behavior is documented. Skip this for AIX.
if (common.isAix) {
common.skip('folder watch capability is limited in AIX.');
return;
}
common.refreshTmpDir();
const fn = '新建文夹件.txt';
const a = path.join(common.tmpDir, fn);
const watchers = new Set();
function registerWatcher(watcher) {
watchers.add(watcher);
}
function unregisterWatcher(watcher) {
watcher.close();
watchers.delete(watcher);
if (watchers.size === 0) {
clearInterval(interval);
}
}
const watcher1 = fs.watch(
common.tmpDir,
{encoding: 'hex'},
(event, filename) => {
if (['e696b0e5bbbae69687e5a4b9e4bbb62e747874', null].includes(filename))
done(watcher1);
}
);
registerWatcher(watcher1);
const watcher2 = fs.watch(
common.tmpDir,
(event, filename) => {
if ([fn, null].includes(filename))
done(watcher2);
}
);
registerWatcher(watcher2);
const watcher3 = fs.watch(
common.tmpDir,
{encoding: 'buffer'},
(event, filename) => {
if (filename instanceof Buffer && filename.toString('utf8') === fn)
done(watcher3);
else if (filename === null)
done(watcher3);
}
);
registerWatcher(watcher3);
const done = common.mustCall(unregisterWatcher, watchers.size);
// OS X and perhaps other systems can have surprising race conditions with
// file events. So repeat the operation in case it is missed the first time.
const interval = setInterval(() => {
const fd = fs.openSync(a, 'w+');
fs.closeSync(fd);
fs.unlinkSync(a);
}, common.platformTimeout(100));