summaryrefslogtreecommitdiff
path: root/test/pummel/test-net-many-clients.js
diff options
context:
space:
mode:
authorMicheil Smith <micheil@brandedcode.com>2010-06-18 10:34:56 -0700
committerRyan Dahl <ry@tinyclouds.org>2010-06-18 10:34:56 -0700
commite0d30b545a737c43097f96446d82374ab2fd1e9a (patch)
treebfe1c66bc6a1b66e001d6241c7efd4d26fb8b1e4 /test/pummel/test-net-many-clients.js
parent3f48276bf9e36d6af5760aeb4fbd1123f6c4f207 (diff)
downloadandroid-node-v8-e0d30b545a737c43097f96446d82374ab2fd1e9a.tar.gz
android-node-v8-e0d30b545a737c43097f96446d82374ab2fd1e9a.tar.bz2
android-node-v8-e0d30b545a737c43097f96446d82374ab2fd1e9a.zip
Renaming tcp tests to net tests
Diffstat (limited to 'test/pummel/test-net-many-clients.js')
-rw-r--r--test/pummel/test-net-many-clients.js81
1 files changed, 81 insertions, 0 deletions
diff --git a/test/pummel/test-net-many-clients.js b/test/pummel/test-net-many-clients.js
new file mode 100644
index 0000000000..9cff30b7ea
--- /dev/null
+++ b/test/pummel/test-net-many-clients.js
@@ -0,0 +1,81 @@
+require("../common");
+net = require("net");
+// 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";
+}
+
+var server = net.createServer(function (c) {
+ c.addListener("connect", function () {
+ total_connections++;
+ print("#");
+ c.write(body);
+ c.end();
+ });
+});
+
+function runClient (callback) {
+ var client = net.createConnection(PORT);
+
+ client.connections = 0;
+
+ client.setEncoding("utf8");
+
+ client.addListener("connect", function () {
+ print("c");
+ client.recved = "";
+ client.connections += 1;
+ });
+
+ client.addListener("data", function (chunk) {
+ this.recved += chunk;
+ });
+
+ client.addListener("end", function () {
+ client.end();
+ });
+
+ client.addListener("error", function (e) {
+ puts("\n\nERROOOOOr");
+ throw e;
+ });
+
+ client.addListener("close", function (had_error) {
+ print(".");
+ assert.equal(false, had_error);
+ assert.equal(bytes, client.recved.length);
+
+ if (client.fd) {
+ puts(client.fd);
+ }
+ assert.ok(!client.fd);
+
+ if (this.connections < connections_per_client) {
+ this.connect(PORT);
+ } else {
+ callback();
+ }
+ });
+}
+
+server.listen(PORT, function () {
+ var finished_clients = 0;
+ for (var i = 0; i < concurrency; i++) {
+ runClient(function () {
+ if (++finished_clients == concurrency) server.close();
+ });
+ }
+});
+
+process.addListener("exit", function () {
+ assert.equal(connections_per_client * concurrency, total_connections);
+ puts("\nokay!");
+});