0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-net-socket-write-after-close.js
kysnm b98aaa312e
net: migrate errors to internal/errors
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>
2017-12-24 02:16:44 +08:00

43 lines
1.0 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
{
const server = net.createServer();
server.listen(common.mustCall(() => {
const port = server.address().port;
const client = net.connect({ port }, common.mustCall(() => {
client.on('error', common.mustCall((err) => {
server.close();
assert.strictEqual(err.constructor, Error);
assert.strictEqual(err.message, 'write EBADF');
}));
client._handle.close();
client.write('foo');
}));
}));
}
{
const server = net.createServer();
server.listen(common.mustCall(() => {
const port = server.address().port;
const client = net.connect({ port }, common.mustCall(() => {
client.on('error', common.expectsError({
code: 'ERR_SOCKET_CLOSED',
message: 'Socket is closed',
type: Error
}));
server.close();
client._handle.close();
client._handle = null;
client.write('foo');
}));
}));
}