aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-net-write-after-end-nt.js
blob: 3f93b444f4cb36808718faea809ea101b8774450 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'use strict';
const common = require('../common');

const assert = require('assert');
const net = require('net');

const { mustCall } = common;

// This test ensures those errors caused by calling `net.Socket.write()`
// after sockets ending will be emitted in the next tick.
const server = net.createServer(mustCall((socket) => {
  socket.end();
})).listen(() => {
  const client = net.connect(server.address().port, () => {
    let hasError = false;
    client.on('error', mustCall((err) => {
      hasError = true;
      server.close();
    }));
    client.on('end', mustCall(() => {
      client.write('hello', mustCall());
      assert(!hasError, 'The error should be emitted in the next tick.');
    }));
    client.end();
  });
});