mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 23:56:58 +00:00

Throw ERR_SOCKET_CLOSED and ERR_SERVER_NOT_RUNNING instead of the old-style errors in net.js. PR-URL: https://github.com/nodejs/node/pull/17766 Refs: https://github.com/nodejs/node/issues/17709 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
29 lines
791 B
JavaScript
29 lines
791 B
JavaScript
'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() {
|
|
// Test destroy returns this, even on multiple calls when it short-circuits.
|
|
assert.strictEqual(conn, conn.destroy().destroy());
|
|
conn.on('error', common.expectsError({
|
|
code: 'ERR_SOCKET_CLOSED',
|
|
message: 'Socket is closed',
|
|
type: Error
|
|
}));
|
|
|
|
conn.write(Buffer.from('kaboom'), common.expectsError({
|
|
code: 'ERR_SOCKET_CLOSED',
|
|
message: 'Socket is closed',
|
|
type: Error
|
|
}));
|
|
server.close();
|
|
}));
|
|
}));
|