2017-05-22 18:03:55 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const net = require('net');
|
|
|
|
const assert = require('assert');
|
|
|
|
|
|
|
|
const server = net.createServer();
|
|
|
|
server.listen(0, common.mustCall(function() {
|
|
|
|
const port = server.address().port;
|
|
|
|
const conn = net.createConnection(port);
|
|
|
|
|
|
|
|
conn.on('connect', common.mustCall(function() {
|
2017-06-07 12:48:35 -07:00
|
|
|
// Test destroy returns this, even on multiple calls when it short-circuits.
|
|
|
|
assert.strictEqual(conn, conn.destroy().destroy());
|
2019-08-18 23:38:35 +02:00
|
|
|
conn.on('error', common.mustNotCall());
|
2017-12-20 08:07:41 +09:00
|
|
|
|
|
|
|
conn.write(Buffer.from('kaboom'), common.expectsError({
|
2018-01-29 19:32:34 +01:00
|
|
|
code: 'ERR_STREAM_DESTROYED',
|
|
|
|
message: 'Cannot call write after a stream was destroyed',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'Error'
|
2017-05-22 18:03:55 +02:00
|
|
|
}));
|
|
|
|
server.close();
|
|
|
|
}));
|
|
|
|
}));
|