Skip to content

Commit

Permalink
test: add coverage for socket write after close
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
  • Loading branch information
cjihrig authored and MylesBorins committed Jul 17, 2017
1 parent 48f00b5 commit cbcc9c1
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/parallel/test-net-socket-write-after-close.js
Original file line number Diff line number Diff line change
@@ -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 cbcc9c1

Please sign in to comment.