Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: test path handling of net.connect
  • Loading branch information
joyeecheung committed Mar 14, 2017
commit b076cfa445c2c3f7310c031f4181da4bb6b5deba
53 changes: 53 additions & 0 deletions test/parallel/test-net-connect-options-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';
const common = require('../common');
const net = require('net');

// This file tests the option handling of net.connect,
// net.createConnect, and new Socket().connect

common.refreshTmpDir();

const CLIENT_VARIANTS = 12;

// Test connect(path)
{
const prefix = `${common.PIPE}-net-connect-options-path`;
const serverPath = `${prefix}-server`;
let counter = 0;
const server = net.createServer()
.on('connection', common.mustCall(function(socket) {
socket.end('ok');
}, CLIENT_VARIANTS))
.listen(serverPath, common.mustCall(function() {
const getConnectCb = () => common.mustCall(function() {
const client = this;
client.end();
client.on('close', common.mustCall(function() {
counter++;
if (counter === CLIENT_VARIANTS) {
server.close();
}
}));
});

// CLIENT_VARIANTS depends on the following code
net.connect(serverPath, getConnectCb());
net.connect(serverPath)
.on('connect', getConnectCb());
net.createConnection(serverPath, getConnectCb());
net.createConnection(serverPath)
.on('connect', getConnectCb());
new net.Socket().connect(serverPath, getConnectCb());
new net.Socket().connect(serverPath)
.on('connect', getConnectCb());
net.connect({path: serverPath}, getConnectCb());
net.connect({path: serverPath})
.on('connect', getConnectCb());
net.createConnection({path: serverPath}, getConnectCb());
net.createConnection({path: serverPath})
.on('connect', getConnectCb());
new net.Socket().connect({path: serverPath}, getConnectCb());
new net.Socket().connect({path: serverPath})
.on('connect', getConnectCb());
}));
}