2010-03-09 00:06:29 +01:00
|
|
|
require("../common");
|
2010-03-10 01:27:49 +01:00
|
|
|
net = require("net");
|
2009-07-15 17:00:15 +02:00
|
|
|
// settings
|
|
|
|
var bytes = 1024*40;
|
|
|
|
var concurrency = 100;
|
|
|
|
var connections_per_client = 5;
|
|
|
|
|
|
|
|
// measured
|
|
|
|
var total_connections = 0;
|
|
|
|
|
|
|
|
var body = "";
|
|
|
|
for (var i = 0; i < bytes; i++) {
|
|
|
|
body += "C";
|
|
|
|
}
|
|
|
|
|
2010-03-10 01:27:49 +01:00
|
|
|
var server = net.createServer(function (c) {
|
2009-07-15 17:00:15 +02:00
|
|
|
c.addListener("connect", function () {
|
|
|
|
total_connections++;
|
|
|
|
print("#");
|
2010-02-16 22:15:30 +01:00
|
|
|
c.write(body);
|
2010-04-08 19:44:22 +02:00
|
|
|
c.end();
|
2009-07-15 17:00:15 +02:00
|
|
|
});
|
|
|
|
});
|
2010-02-26 21:06:32 +01:00
|
|
|
server.listen(PORT);
|
2009-07-15 17:00:15 +02:00
|
|
|
|
|
|
|
function runClient (callback) {
|
2010-03-10 01:27:49 +01:00
|
|
|
var client = net.createConnection(PORT);
|
|
|
|
|
2009-07-15 17:00:15 +02:00
|
|
|
client.connections = 0;
|
2010-03-10 01:27:49 +01:00
|
|
|
|
2009-07-15 17:00:15 +02:00
|
|
|
client.setEncoding("utf8");
|
|
|
|
|
|
|
|
client.addListener("connect", function () {
|
2009-08-19 17:28:41 +02:00
|
|
|
print("c");
|
2009-07-15 17:00:15 +02:00
|
|
|
client.recved = "";
|
|
|
|
client.connections += 1;
|
|
|
|
});
|
|
|
|
|
2010-02-12 09:25:15 +01:00
|
|
|
client.addListener("data", function (chunk) {
|
2009-07-15 17:00:15 +02:00
|
|
|
this.recved += chunk;
|
|
|
|
});
|
|
|
|
|
2010-03-10 01:27:49 +01:00
|
|
|
client.addListener("end", function () {
|
2010-04-08 19:44:22 +02:00
|
|
|
client.end();
|
2009-07-15 17:00:15 +02:00
|
|
|
});
|
|
|
|
|
2010-03-10 01:27:49 +01:00
|
|
|
client.addListener("error", function (e) {
|
|
|
|
puts("\n\nERROOOOOr");
|
|
|
|
throw e;
|
|
|
|
});
|
|
|
|
|
2009-08-14 12:51:46 +02:00
|
|
|
client.addListener("close", function (had_error) {
|
2009-07-15 17:00:15 +02:00
|
|
|
print(".");
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(false, had_error);
|
|
|
|
assert.equal(bytes, client.recved.length);
|
2010-03-10 01:27:49 +01:00
|
|
|
|
|
|
|
if (client.fd) {
|
|
|
|
puts(client.fd);
|
|
|
|
}
|
|
|
|
assert.ok(!client.fd);
|
|
|
|
|
2009-07-15 17:00:15 +02:00
|
|
|
if (this.connections < connections_per_client) {
|
2010-02-26 21:06:32 +01:00
|
|
|
this.connect(PORT);
|
2009-07-15 17:00:15 +02:00
|
|
|
} else {
|
2009-08-26 22:03:19 +02:00
|
|
|
callback();
|
2009-07-15 17:00:15 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-03-10 01:27:49 +01:00
|
|
|
server.addListener('listening', function () {
|
|
|
|
var finished_clients = 0;
|
|
|
|
for (var i = 0; i < concurrency; i++) {
|
|
|
|
runClient(function () {
|
|
|
|
if (++finished_clients == concurrency) server.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2009-07-15 17:00:15 +02:00
|
|
|
|
2009-08-26 18:51:04 +02:00
|
|
|
process.addListener("exit", function () {
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(connections_per_client * concurrency, total_connections);
|
2009-07-15 17:00:15 +02:00
|
|
|
puts("\nokay!");
|
2009-08-26 18:51:04 +02:00
|
|
|
});
|