-
Notifications
You must be signed in to change notification settings - Fork 2
Closed
Description
Haven't diagnosed, but:
var test = require(process.argv[2]),
net = require('net');
test('client-basic', function (t) {
// API checks
t.ok(net.createConnection, "method available");
t.ok(net.connect, "method available");
// see http://nodejs.org/api/net.html#net_net_connect_options_connectionlistener
// connects
var client = net.connect(80, "ipcalf.com", function () {
t.pass("callback called");
});
t.ok(client instanceof net.Socket, "returned socket");
client.on('connect', function () {
t.pass("socket connected");
client.write("GET / HTTP/1.1\nHost: ipcalf.com\nAccept: text/plain\n\n");
});
client.on('error', function () {
t.fail("socket error");
});
// lives/dies
client.on('data', function (d) {
t.equal(d.slice(0,8).toString(), "HTTP/1.1", "got response");
client.end();
});
client.on('end', function () {
t.ok(true, "socket closed");
t.end();
});
});
test('server-basic', function (t) {
// API checks
t.ok(net.createServer, "method available");
// see http://nodejs.org/api/net.html#net_net_createserver_options_connectionlistener
// listening
var server = net.createServer(function (c) {
t.pass("connection callback called");
});
server.listen(0, function () {
t.pass("listening callback called");
});
server.on('listening', function () {
t.pass("got listening event");
t.ok(server.address().port, "port assigned");
testConnection(server.address().port);
});
// connecting
server.on('connection', function (c) {
t.ok(c instanceof net.Socket, "got connection");
c.on('end', function () {
t.pass("disconnected");
});
c.end("«§»");
});
function testConnection(port) {
net.connect(port).on('data', function (d) {
t.equal(d.toString(), "«§»");
t.end();
});
}
});Before:
postel:runtime natevw$ node test/suite/net.js ttt
# client-basic
ok 1 ok
ok 2 ok
ok 3 ok
ok 4 ok
ok 5 ok
ok 6 equal
ok 7 ok
# server-basic
ok 8 ok
ok 9 ok
ok 10 ok
ok 11 ok
ok 12 ok
ok 13 ok
ok 14 equal
0.. 14
# pass 14 14
# fail 0 14
After:
postel:runtime natevw$ node test/suite/net.js tinytap
# client-basic
ok 1 ok
ok 2 ok
ok 3 ok
ok 4 equal
ok 5 ok
# server-basic
ok 6 ok
ok 7 ok
ok 8 ok
ok 9 equal
# pass 9 9
# fail 0 9
Metadata
Metadata
Assignees
Labels
No labels