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 <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 28, 2017
1 parent a7f5c9c commit d0dbd53
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 d0dbd53

Please sign in to comment.