0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/http/http_server_for_chunky_client.js
Brian White a081c7c522 benchmark: fix chunky client benchmark execution
This commit fixes a few things for this benchmark:

1. Ensures the temporary directory for the unix socket exists.
2. Prevents the client code from being run directly because the
server script is the one that calls out the client code.
3. Ensures the server is closed once the client benchmarks have
finished.
4. Since this is an http benchmark, it should be moved to the http
benchmarks subdirectory.

PR-URL: https://github.com/iojs/io.js/pull/1257
Reviewed-By: Roman Reiss <me@silverwind.io>
2015-04-03 00:56:45 -04:00

55 lines
1.1 KiB
JavaScript

'use strict';
var path = require('path');
var http = require('http');
var fs = require('fs');
var spawn = require('child_process').spawn;
var common = require('../common.js')
var test = require('../../test/common.js')
var pep = path.dirname(process.argv[1]) + '/_chunky_http_client.js';
var PIPE = test.PIPE;
try {
fs.accessSync(test.tmpDir, fs.F_OK);
} catch (e) {
fs.mkdirSync(test.tmpDir);
}
var server;
try {
fs.unlinkSync(PIPE);
} catch (e) { /* ignore */ }
server = http.createServer(function(req, res) {
res.writeHead(200, { 'content-type': 'text/plain',
'content-length': '2' });
res.end('ok');
});
server.on('error', function(err) {
throw new Error('server error: ' + err);
});
try {
var child;
server.listen(PIPE);
child = spawn(process.execPath, [pep], { });
child.on('error', function(err) {
throw new Error('spawn error: ' + err );
});
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
child.on('close', function (exitCode) {
server.close();
});
} catch(e) {
throw new Error('error: ' + e );
}