11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst net = require('net');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst server = net.createServer();
71cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(function() {
81cb0ef41Sopenharmony_ci  const port = server.address().port;
91cb0ef41Sopenharmony_ci  const conn = net.createConnection(port);
101cb0ef41Sopenharmony_ci  server.on('connection', (socket) => {
111cb0ef41Sopenharmony_ci    socket.on('error', common.expectsError({
121cb0ef41Sopenharmony_ci      code: 'ECONNRESET',
131cb0ef41Sopenharmony_ci      message: 'read ECONNRESET',
141cb0ef41Sopenharmony_ci      name: 'Error'
151cb0ef41Sopenharmony_ci    }));
161cb0ef41Sopenharmony_ci  });
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci  conn.on('connect', common.mustCall(function() {
191cb0ef41Sopenharmony_ci    assert.strictEqual(conn, conn.resetAndDestroy().destroy());
201cb0ef41Sopenharmony_ci    conn.on('error', common.mustNotCall());
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci    conn.write(Buffer.from('fzfzfzfzfz'), common.expectsError({
231cb0ef41Sopenharmony_ci      code: 'ERR_STREAM_DESTROYED',
241cb0ef41Sopenharmony_ci      message: 'Cannot call write after a stream was destroyed',
251cb0ef41Sopenharmony_ci      name: 'Error'
261cb0ef41Sopenharmony_ci    }));
271cb0ef41Sopenharmony_ci    server.close();
281cb0ef41Sopenharmony_ci  }));
291cb0ef41Sopenharmony_ci}));
30