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-constructor.js
Santiago Gimeno 67e2a15d75
net: honor default values in Socket constructor
Specifically `readable` and `writable` that default to `false`.

PR-URL: https://github.com/nodejs/node/pull/19971
Fixes: https://github.com/libuv/libuv/issues/1794
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
2018-04-23 17:15:07 +02:00

44 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
function test(sock, readable, writable) {
let socket;
if (sock instanceof net.Socket) {
socket = sock;
} else {
socket = new net.Socket(sock);
socket.unref();
}
assert.strictEqual(socket.readable, readable);
assert.strictEqual(socket.writable, writable);
}
test(undefined, false, false);
const server = net.createServer(common.mustCall((socket) => {
test(socket, true, true);
test({ handle: socket._handle }, false, false);
test({ handle: socket._handle, readable: true, writable: true }, true, true);
if (socket._handle.fd >= 0) {
test(socket._handle.fd, false, false);
test({ fd: socket._handle.fd }, false, false);
test({ fd: socket._handle.fd, readable: true, writable: true }, true, true);
}
server.close();
}));
server.listen(common.mustCall(() => {
const { port } = server.address();
const socket = net.connect(port, common.mustCall(() => {
test(socket, true, true);
socket.end();
}));
test(socket, false, true);
}));