Skip to content

Commit

Permalink
Updated to Node 10.8.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Aug 6, 2018
1 parent 118e277 commit 67abc03
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 54 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ npm install --save readable-stream

This package is a mirror of the streams implementations in Node.js.

Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v10.6.0/docs/api/stream.html).
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v10.8.0/docs/api/stream.html).

If you want to guarantee a stable streams base, regardless of what version of
Node you, or the users of your libraries are using, use **readable-stream** *only* and avoid the *"stream"* module in Node-core, for background see [this blogpost](http://r.va.gg/2014/06/why-i-dont-use-nodes-core-stream-module.html).
Expand Down
6 changes: 3 additions & 3 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
};

function pipeOnDrain(src) {
return function () {
return function pipeOnDrainFunctionResult() {
var state = src._readableState;
debug('pipeOnDrain', state.awaitDrain);
if (state.awaitDrain) state.awaitDrain--;
Expand Down Expand Up @@ -912,8 +912,8 @@ Readable.prototype.wrap = function (stream) {
// important when wrapping filters and duplexes.
for (var i in stream) {
if (this[i] === undefined && typeof stream[i] === 'function') {
this[i] = function (method) {
return function () {
this[i] = function methodWrap(method) {
return function methodWrapReturnFunction() {
return stream[method].apply(stream, arguments);
};
}(i);
Expand Down
2 changes: 1 addition & 1 deletion lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ WritableState.prototype.getBuffer = function getBuffer() {
(function () {
try {
Object.defineProperty(WritableState.prototype, 'buffer', {
get: internalUtil.deprecate(function () {
get: internalUtil.deprecate(function writableStateBufferGetter() {
return this.getBuffer();
}, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
});
Expand Down
67 changes: 60 additions & 7 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This directory contains modules used to test the Node.js implementation.
* [DNS module](#dns-module)
* [Duplex pair helper](#duplex-pair-helper)
* [Fixtures module](#fixtures-module)
* [Heap dump checker module](#heap-dump-checker-module)
* [HTTP2 module](#http2-module)
* [Internet module](#internet-module)
* [tmpdir module](#tmpdir-module)
Expand Down Expand Up @@ -58,18 +59,19 @@ symlinks
([SeCreateSymbolicLinkPrivilege](https://msdn.microsoft.com/en-us/library/windows/desktop/bb530716(v=vs.85).aspx)).
On non-Windows platforms, this always returns `true`.

### crashOnUnhandledRejection()

Installs a `process.on('unhandledRejection')` handler that crashes the process
after a tick. This is useful for tests that use Promises and need to make sure
no unexpected rejections occur, because currently they result in silent
failures.

### ddCommand(filename, kilobytes)
* return [<Object>]

Platform normalizes the `dd` command

### disableCrashOnUnhandledRejection()

Removes the `process.on('unhandledRejection')` handler that crashes the process
after a tick. The handler is useful for tests that use Promises and need to make
sure no unexpected rejections occur, because currently they result in silent
failures. However, it is useful in some rare cases to disable it, for example if
the `unhandledRejection` hook is directly used by the test.

### enoughTestMem
* [<boolean>]

Expand Down Expand Up @@ -325,6 +327,21 @@ otherwise.
### noWarnCode
See `common.expectWarning()` for usage.

### onGC(target, listener)
* `target` [<Object>]
* `listener` [<Object>]
* `ongc` [<Function>]

Installs a GC listener for the collection of `target`.

This uses `async_hooks` for GC tracking. This means that it enables
`async_hooks` tracking, which may affect the test functionality. It also
means that between a `global.gc()` call and the listener being invoked
a full `setImmediate()` invocation passes.

`listener` is an object to make it easier to use a closure; the target object
should not be in scope when `listener.ongc()` is created.

### opensslCli
* [<boolean>]

Expand Down Expand Up @@ -542,6 +559,42 @@ Returns the result of
Returns the result of
`fs.readFileSync(path.join(fixtures.fixturesDir, 'keys', arg), 'enc')`.

## Heap dump checker module

This provides utilities for checking the validity of heap dumps.
This requires the usage of `--expose-internals`.

### heap.recordState()

Create a heap dump and an embedder graph copy for inspection.
The returned object has a `validateSnapshotNodes` function similar to the
one listed below. (`heap.validateSnapshotNodes(...)` is a shortcut for
`heap.recordState().validateSnapshotNodes(...)`.)

### heap.validateSnapshotNodes(name, expected, options)

* `name` [<string>] Look for this string as the name of heap dump nodes.
* `expected` [<Array>] A list of objects, possibly with an `children`
property that points to expected other adjacent nodes.
* `options` [<Array>]
* `loose` [<boolean>] Do not expect an exact listing of occurrences
of nodes with name `name` in `expected`.

Create a heap dump and an embedder graph copy and validate occurrences.

<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
```js
validateSnapshotNodes('TLSWRAP', [
{
children: [
{ name: 'enc_out' },
{ name: 'enc_in' },
{ name: 'TLSWrap' }
]
}
]);
```

## HTTP/2 Module

The http2.js module provides a handful of utilities for creating mock HTTP/2
Expand Down
206 changes: 206 additions & 0 deletions test/common/heap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
'use strict';

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

/*<replacement>*/
require('babel-polyfill');
var util = require('util');
for (var i in util) {
exports[i] = util[i];
} /*</replacement>*/ /* eslint-disable node-core/required-modules */
'use strict';

/*<replacement>*/
var objectKeys = objectKeys || function (obj) {
var keys = [];
for (var key in obj) {
keys.push(key);
}return keys;
};
/*</replacement>*/

var assert = require('assert');

/*<replacement>*/
var util = require('core-util-is');
util.inherits = require('inherits');
/*</replacement>*/

var internalTestHeap = void 0;
try {
internalTestHeap = require('internal/test/heap');
} catch (e) {
console.log('using `test/common/heap.js` requires `--expose-internals`');
throw e;
}
var _internalTestHeap = internalTestHeap,
createJSHeapDump = _internalTestHeap.createJSHeapDump,
buildEmbedderGraph = _internalTestHeap.buildEmbedderGraph;

var State = function () {
function State() {
_classCallCheck(this, State);

this.snapshot = createJSHeapDump();
this.embedderGraph = buildEmbedderGraph();
}

State.prototype.validateSnapshotNodes = function validateSnapshotNodes(name, expected) {
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
_ref$loose = _ref.loose,
loose = _ref$loose === undefined ? false : _ref$loose;

var snapshot = this.snapshot.filter(function (node) {
return node.name === 'Node / ' + name && node.type !== 'string';
});
if (loose) assert(snapshot.length >= expected.length);else assert.strictEqual(snapshot.length, expected.length);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;

try {
for (var _iterator = expected[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var expectedNode = _step.value;

if (expectedNode.children) {
var _loop = function (expectedChild) {
var check = typeof expectedChild === 'function' ? expectedChild : function (node) {
return [expectedChild.name, 'Node / ' + expectedChild.name].includes(node.name);
};

assert(snapshot.some(function (node) {
return node.outgoingEdges.map(function (edge) {
return edge.toNode;
}).some(check);
}), 'expected to find child ' + util.inspect(expectedChild) + ' ' + ('in ' + util.inspect(snapshot)));
};

var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;

try {
for (var _iterator3 = expectedNode.children[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var expectedChild = _step3.value;

_loop(expectedChild);
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}

var graph = this.embedderGraph.filter(function (node) {
return node.name === name;
});
if (loose) assert(graph.length >= expected.length);else assert.strictEqual(graph.length, expected.length);
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;

try {
for (var _iterator2 = expected[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _expectedNode = _step2.value;

if (_expectedNode.edges) {
var _loop2 = function (_expectedChild) {
var check = typeof _expectedChild === 'function' ? _expectedChild : function (node) {
return node.name === _expectedChild.name || node.value && node.value.constructor && node.value.constructor.name === _expectedChild.name;
};

assert(graph.some(function (node) {
return node.edges.some(check);
}), 'expected to find child ' + util.inspect(_expectedChild) + ' ' + ('in ' + util.inspect(snapshot)));
};

var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;

try {
for (var _iterator4 = _expectedNode.children[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var _expectedChild = _step4.value;

_loop2(_expectedChild);
}
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
}
}
}
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
};

return State;
}();

function recordState() {
return new State();
}

function validateSnapshotNodes() {
var _recordState;

return (_recordState = recordState()).validateSnapshotNodes.apply(_recordState, arguments);
}

module.exports = {
recordState: recordState,
validateSnapshotNodes: validateSnapshotNodes
};

function forEach(xs, f) {
for (var i = 0, l = xs.length; i < l; i++) {
f(xs[i], i);
}
}
39 changes: 33 additions & 6 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,12 +911,12 @@ exports.getBufferSources = function getBufferSources(buf) {
};

// Crash the process on unhandled rejections.
exports.crashOnUnhandledRejection = function () {
process.on('unhandledRejection', function (err) {
return process.nextTick(function () {
throw err;
});
});
var crashOnUnhandledRejection = function (err) {
throw err;
};
process.on('unhandledRejection', crashOnUnhandledRejection);
exports.disableCrashOnUnhandledRejection = function () {
process.removeListener('unhandledRejection', crashOnUnhandledRejection);
};

exports.getTTYfd = function getTTYfd() {
Expand Down Expand Up @@ -981,6 +981,33 @@ exports.restoreStdout = restoreWritable.bind(null, 'stdout');
exports.restoreStderr = restoreWritable.bind(null, 'stderr');
exports.isCPPSymbolsNotMapped = exports.isWindows || exports.isSunOS || exports.isAIX || exports.isLinuxPPCBE || exports.isFreeBSD;

var gcTrackerMap = new WeakMap();
var gcTrackerTag = 'NODE_TEST_COMMON_GC_TRACKER';

exports.onGC = function (obj, gcListener) {
var async_hooks = require('async_hooks');

var onGcAsyncHook = async_hooks.createHook({
init: exports.mustCallAtLeast(function (id, type, trigger, resource) {
if (this.trackedId === undefined) {
assert.strictEqual(type, gcTrackerTag);
this.trackedId = id;
}
}),
destroy: function (id) {
assert.notStrictEqual(this.trackedId, -1);
if (id === this.trackedId) {
this.gcListener.ongc();
onGcAsyncHook.disable();
}
}
}).enable();
onGcAsyncHook.gcListener = gcListener;

gcTrackerMap.set(obj, new async_hooks.AsyncResource(gcTrackerTag));
obj = null;
};

function forEach(xs, f) {
for (var i = 0, l = xs.length; i < l; i++) {
f(xs[i], i);
Expand Down

0 comments on commit 67abc03

Please sign in to comment.