2011-03-10 09:54:52 +01:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2010-12-05 00:20:34 +01:00
|
|
|
var common = require('../common');
|
2010-12-05 23:33:52 +01:00
|
|
|
var assert = require('assert');
|
2010-12-05 01:11:57 +01:00
|
|
|
var net = require('net');
|
|
|
|
|
2009-07-15 17:00:15 +02:00
|
|
|
// settings
|
2010-12-03 02:03:18 +01:00
|
|
|
var bytes = 1024 * 40;
|
2009-07-15 17:00:15 +02:00
|
|
|
var concurrency = 100;
|
|
|
|
var connections_per_client = 5;
|
|
|
|
|
|
|
|
// measured
|
|
|
|
var total_connections = 0;
|
|
|
|
|
2010-12-03 02:03:18 +01:00
|
|
|
var body = '';
|
2009-07-15 17:00:15 +02:00
|
|
|
for (var i = 0; i < bytes; i++) {
|
2010-12-03 02:03:18 +01:00
|
|
|
body += 'C';
|
2009-07-15 17:00:15 +02:00
|
|
|
}
|
|
|
|
|
2010-12-03 02:03:18 +01:00
|
|
|
var server = net.createServer(function(c) {
|
2011-10-15 01:08:36 +02:00
|
|
|
c.on('connect', function() {
|
2009-07-15 17:00:15 +02:00
|
|
|
total_connections++;
|
2010-12-03 02:03:18 +01:00
|
|
|
common.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-12-03 02:03:18 +01:00
|
|
|
function runClient(callback) {
|
2010-07-15 20:47:25 +02:00
|
|
|
var client = net.createConnection(common.PORT);
|
2010-03-10 01:27:49 +01:00
|
|
|
|
2009-07-15 17:00:15 +02:00
|
|
|
client.connections = 0;
|
2010-03-10 01:27:49 +01:00
|
|
|
|
2010-12-03 02:03:18 +01:00
|
|
|
client.setEncoding('utf8');
|
2009-07-15 17:00:15 +02:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
client.on('connect', function() {
|
2010-12-03 02:03:18 +01:00
|
|
|
common.print('c');
|
|
|
|
client.recved = '';
|
2009-07-15 17:00:15 +02:00
|
|
|
client.connections += 1;
|
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
client.on('data', function(chunk) {
|
2009-07-15 17:00:15 +02:00
|
|
|
this.recved += chunk;
|
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
client.on('end', function() {
|
2010-04-08 19:44:22 +02:00
|
|
|
client.end();
|
2009-07-15 17:00:15 +02:00
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
client.on('error', function(e) {
|
2010-12-03 02:03:18 +01:00
|
|
|
console.log('\n\nERROOOOOr');
|
2010-03-10 01:27:49 +01:00
|
|
|
throw e;
|
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
client.on('close', function(had_error) {
|
2010-12-03 02:03:18 +01:00
|
|
|
common.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) {
|
2010-06-24 02:40:51 +02:00
|
|
|
console.log(client.fd);
|
2010-03-10 01:27:49 +01:00
|
|
|
}
|
|
|
|
assert.ok(!client.fd);
|
|
|
|
|
2009-07-15 17:00:15 +02:00
|
|
|
if (this.connections < connections_per_client) {
|
2010-07-15 20:47:25 +02:00
|
|
|
this.connect(common.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-12-03 02:03:18 +01:00
|
|
|
server.listen(common.PORT, function() {
|
2010-03-10 01:27:49 +01:00
|
|
|
var finished_clients = 0;
|
|
|
|
for (var i = 0; i < concurrency; i++) {
|
2010-12-03 02:03:18 +01:00
|
|
|
runClient(function() {
|
2010-03-10 01:27:49 +01:00
|
|
|
if (++finished_clients == concurrency) server.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2009-07-15 17:00:15 +02:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
process.on('exit', function() {
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(connections_per_client * concurrency, total_connections);
|
2010-12-03 02:03:18 +01:00
|
|
|
console.log('\nokay!');
|
2009-08-26 18:51:04 +02:00
|
|
|
});
|