Skip to content
Permalink
Browse files

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: #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>
  • Loading branch information...
cjihrig authored and jasnell committed May 23, 2017
1 parent a7f5c9c commit d0dbd53eb0de579ad4bb4e7b7fa047664144c7c7
Showing with 39 additions and 0 deletions.
  1. +39 −0 test/parallel/test-net-socket-write-after-close.js
@@ -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');
}));
}));
}

0 comments on commit d0dbd53

Please sign in to comment.
You can’t perform that action at this time.