2017-01-03 22:16:48 +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.
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-12-31 00:38:06 +01:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const net = require('net');
|
2010-12-05 01:11:57 +01:00
|
|
|
|
2009-07-15 17:00:15 +02:00
|
|
|
// settings
|
2017-01-08 14:19:00 +01:00
|
|
|
const bytes = 1024 * 40;
|
|
|
|
const concurrency = 100;
|
|
|
|
const connections_per_client = 5;
|
2009-07-15 17:00:15 +02:00
|
|
|
|
|
|
|
// measured
|
2017-01-08 14:19:00 +01:00
|
|
|
let total_connections = 0;
|
2009-07-15 17:00:15 +02:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const body = 'C'.repeat(bytes);
|
2009-07-15 17:00:15 +02:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const server = net.createServer(function(c) {
|
2013-05-07 01:37:03 +02:00
|
|
|
console.log('connected');
|
|
|
|
total_connections++;
|
2015-09-27 01:16:35 +02:00
|
|
|
console.log('#');
|
2013-05-07 01:37:03 +02:00
|
|
|
c.write(body);
|
|
|
|
c.end();
|
2009-07-15 17:00:15 +02:00
|
|
|
});
|
|
|
|
|
2010-12-03 02:03:18 +01:00
|
|
|
function runClient(callback) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const 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() {
|
2015-09-27 01:16:35 +02:00
|
|
|
console.log('c');
|
2010-12-03 02:03:18 +01:00
|
|
|
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) {
|
2015-09-27 01:16:35 +02:00
|
|
|
console.log('.');
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(false, had_error);
|
|
|
|
assert.strictEqual(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() {
|
2017-01-08 14:19:00 +01:00
|
|
|
let finished_clients = 0;
|
|
|
|
for (let i = 0; i < concurrency; i++) {
|
2010-12-03 02:03:18 +01:00
|
|
|
runClient(function() {
|
2016-08-17 06:11:22 +02:00
|
|
|
if (++finished_clients === concurrency) server.close();
|
2010-03-10 01:27:49 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2009-07-15 17:00:15 +02:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
process.on('exit', function() {
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(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
|
|
|
});
|