node/test/parallel/test-net-end-close.js
Anna Henningsen 1365f657b5
src: improve StreamBase read throughput
Improve performance by providing JS with the raw ingridients
for the read data, i.e. an `ArrayBuffer` + offset + length
fields, instead of creating `Buffer` instances in C++ land.

PR-URL: https://github.com/nodejs/node/pull/23797
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-10-24 09:57:42 +02:00

37 lines
800 B
JavaScript

// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const net = require('net');
const { internalBinding } = require('internal/test/binding');
const { UV_EOF } = internalBinding('uv');
const { streamBaseState, kReadBytesOrError } = internalBinding('stream_wrap');
const s = new net.Socket({
handle: {
readStart: function() {
setImmediate(() => {
streamBaseState[kReadBytesOrError] = UV_EOF;
this.onread();
});
},
close: (cb) => setImmediate(cb)
},
writable: false
});
assert.strictEqual(s, s.resume());
const events = [];
s.on('end', () => {
events.push('end');
});
s.on('close', () => {
events.push('close');
});
process.on('exit', () => {
assert.deepStrictEqual(events, [ 'end', 'close' ]);
});