0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

test: add coverage for socket write after close

This commit adds test coverage for the scenario where a socket's
handle has been closed prior to writing.

PR-URL: https://github.com/nodejs/node/pull/13171
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
cjihrig 2017-05-23 11:51:41 -04:00
parent 0aa7ef5950
commit 6a18c1d8dd

View File

@ -0,0 +1,39 @@
'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.mustCall((err) => {
server.close();
assert.strictEqual(err.constructor, Error);
assert.strictEqual(err.message, 'This socket is closed');
}));
client._handle.close();
client._handle = null;
client.write('foo');
}));
}));
}