Skip to content
Browse files

getting rid of a memory leak by creating a new client per request

  • Loading branch information...
1 parent bc647f9 commit 4ab0715d181bb2a2e017238d6f28634058d2f321 @masylum committed Jan 29, 2012
Showing with 9 additions and 7 deletions.
  1. +2 −1 lib/helpers/call.js
  2. +1 −3 lib/testosterone.js
  3. +6 −3 tests/api.js
View
3 lib/helpers/call.js
@@ -1,6 +1,6 @@
var _util = require('util');
-module.exports = function call(_client, _assert, _test, _responses) {
+module.exports = function call(_config, _assert, _test, _responses) {
/**
* Does an http call
@@ -37,6 +37,7 @@ module.exports = function call(_client, _assert, _test, _responses) {
, data = req.data || req.body
, requestTimeout = req.timeout || 0
, headers = req.headers || {}
+ , _client = require('http').createClient(_config.port, _config.host)
, request;
if (data && typeof data === 'object') {
View
4 lib/testosterone.js
@@ -20,7 +20,6 @@ module.exports = function (config) {
, _after
, _call
, _config
- , _client
, _time = Date.now()
, TESTOSTERONE = {}
@@ -99,8 +98,7 @@ module.exports = function (config) {
, title: true
}, config.output);
- _client = require('http').createClient(_config.port, _config.host);
- _call = require('./helpers/call')(_client, _assert, _test, _responses);
+ _call = require('./helpers/call')(_config, _assert, _test, _responses);
if (_config.output.title) {
console.log(('' + (_config.title) + ' :').inverse.yellow + ' ');
View
9 tests/api.js
@@ -1,12 +1,15 @@
var testosterone = require('../lib/testosterone')({port: 3000})
, assert = testosterone.assert;
-testosterone
+// test memory leaks
+(Array(10).join('.').split('')).forEach(function () {
// test async get
- .get('/', function (res) {
+ testosterone.get('/', function (res) {
assert.equal(res.statusCode, 200);
- })
+ });
+});
+testosterone
// test sync get
.get('/hi', function (res) {
assert.equal(res.statusCode, 500);

0 comments on commit 4ab0715

Please sign in to comment.
Something went wrong with that request. Please try again.