1'use strict';
2
3const common = require('../common');
4const net = require('net');
5const assert = require('assert');
6
7const server = net.createServer();
8server.listen(0, common.mustCall(() => {
9  const port = server.address().port;
10  const conn = net.createConnection(port);
11  server.on('connection', (socket) => {
12    socket.on('error', common.expectsError({
13      code: 'ECONNRESET',
14      message: 'read ECONNRESET',
15      name: 'Error'
16    }));
17  });
18
19  conn.on('connect', common.mustCall(() => {
20    assert.strictEqual(conn, conn.resetAndDestroy().destroy());
21    conn.on('error', common.mustNotCall());
22
23    conn.write(Buffer.from('fzfzfzfzfz'), common.expectsError({
24      code: 'ERR_STREAM_DESTROYED',
25      message: 'Cannot call write after a stream was destroyed',
26      name: 'Error'
27    }));
28    server.close();
29  }));
30}));
31