• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --expose-internals
2'use strict';
3require('../common');
4const assert = require('assert');
5const net = require('net');
6
7const { internalBinding } = require('internal/test/binding');
8const { UV_EOF } = internalBinding('uv');
9const { streamBaseState, kReadBytesOrError } = internalBinding('stream_wrap');
10
11const s = new net.Socket({
12  handle: {
13    readStart: function() {
14      setImmediate(() => {
15        streamBaseState[kReadBytesOrError] = UV_EOF;
16        this.onread();
17      });
18    },
19    close: (cb) => setImmediate(cb)
20  },
21  writable: false
22});
23assert.strictEqual(s, s.resume());
24
25const events = [];
26
27s.on('end', () => {
28  events.push('end');
29});
30s.on('close', () => {
31  events.push('close');
32});
33
34process.on('exit', () => {
35  assert.deepStrictEqual(events, [ 'end', 'close' ]);
36});
37