mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
8185e1fd25
include() should not be used by libraries because it will pollute the global namespace. To discourage this behavior and bring Node more in-line with the current CommonJS module system, include() is removed. Small scripts like unit tests often times do want to pollute the global namespace for ease. To avoid the boiler plate code of var x = require("/x.js"); var foo = x.foo; var bar = x.bar; The function node.mixin() is stolen from jQuery's jQuery.extend. So that it can be written: node.mixin(require("/x.js")); Reference: http://docs.jquery.com/Utilities/jQuery.extend http://groups.google.com/group/nodejs/browse_thread/thread/f9ac83e5c11e7e87
70 lines
1.4 KiB
JavaScript
70 lines
1.4 KiB
JavaScript
node.mixin(require("common.js"));
|
|
tcp = require("/tcp.js");
|
|
// settings
|
|
var port = 20743;
|
|
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";
|
|
}
|
|
|
|
var server = tcp.createServer(function (c) {
|
|
c.addListener("connect", function () {
|
|
total_connections++;
|
|
print("#");
|
|
c.send(body);
|
|
c.close();
|
|
});
|
|
});
|
|
server.listen(port);
|
|
|
|
function runClient (callback) {
|
|
var client = tcp.createConnection(port);
|
|
client.connections = 0;
|
|
client.setEncoding("utf8");
|
|
|
|
client.addListener("connect", function () {
|
|
print("c");
|
|
client.recved = "";
|
|
client.connections += 1;
|
|
});
|
|
|
|
client.addListener("receive", function (chunk) {
|
|
this.recved += chunk;
|
|
});
|
|
|
|
client.addListener("eof", function (had_error) {
|
|
client.close();
|
|
});
|
|
|
|
client.addListener("close", function (had_error) {
|
|
print(".");
|
|
assertFalse(had_error);
|
|
assertEquals(bytes, client.recved.length);
|
|
if (this.connections < connections_per_client) {
|
|
this.connect(port);
|
|
} else {
|
|
callback();
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
var finished_clients = 0;
|
|
for (var i = 0; i < concurrency; i++) {
|
|
runClient(function () {
|
|
if (++finished_clients == concurrency) server.close();
|
|
});
|
|
}
|
|
|
|
process.addListener("exit", function () {
|
|
assertEquals(connections_per_client * concurrency, total_connections);
|
|
puts("\nokay!");
|
|
});
|