From 5dd720cc2138810790fcc0a1bfb918c27a1a4e68 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Fri, 15 Aug 2014 01:37:46 +0400 Subject: [PATCH] add stuff for testing against fd leaks and memory leaks --- lib/cli.js | 3 ++- lib/index.js | 15 +++++++++++++++ test/functional/config-1.yaml | 3 +++ test/functional/config-2.yaml | 3 +++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/cli.js b/lib/cli.js index b329c4c78..d5f2f7454 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -21,6 +21,7 @@ var pkg_file = '../package.yaml' , commander = require('commander') , server = require('./index') , crypto = require('crypto') + , Path = require('path') , pkg = yaml.safeLoad(fs.readFileSync(__dirname + '/' + pkg_file, 'utf8')) commander @@ -101,7 +102,7 @@ function get_hostport() { function afterConfigLoad() { if (!config.user_agent) config.user_agent = 'Sinopia/'+pkg.version - if (!config.self_path) config.self_path = config_path + if (!config.self_path) config.self_path = Path.resolve(config_path) logger.setup(config.logs) diff --git a/lib/index.js b/lib/index.js index 78070b26b..48ce0b2cf 100644 --- a/lib/index.js +++ b/lib/index.js @@ -498,6 +498,21 @@ module.exports = function(config_hash) { }) }) + // hook for tests only + if (config._debug) { + app.get('/-/_debug', function(req, res) { + var do_gc = typeof(global.gc) !== 'undefined' + if (do_gc) global.gc() + res.send({ + pid: process.pid, + main: process.mainModule.filename, + conf: config.self_path, + mem: process.memoryUsage(), + gc: do_gc, + }) + }) + } + app.use(app.router) app.use(function(err, req, res, next) { if (typeof(res.report_error) !== 'function') { diff --git a/test/functional/config-1.yaml b/test/functional/config-1.yaml index 9be3bfa98..4a77633ca 100644 --- a/test/functional/config-1.yaml +++ b/test/functional/config-1.yaml @@ -57,3 +57,6 @@ packages: allow_access: none listen: 55551 + +# expose internal methods +_debug: true diff --git a/test/functional/config-2.yaml b/test/functional/config-2.yaml index a55dd59c0..dbf9c7a76 100644 --- a/test/functional/config-2.yaml +++ b/test/functional/config-2.yaml @@ -37,3 +37,6 @@ packages: allow_publish: test anonymous listen: 55552 + +# expose internal methods +_debug: true