Skip to content

Commit

Permalink
integrated memory-usage.js into test.js
Browse files Browse the repository at this point in the history
added linear regression test to detect memory leaks
  • Loading branch information
ben-page committed Aug 8, 2016
1 parent 2ef1c73 commit 5f602c4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 29 deletions.
29 changes: 0 additions & 29 deletions test/memory-usage.js

This file was deleted.

45 changes: 45 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var assert = require('assert');
var Request = require('tedious').Request;
var ConnectionPool = require('../lib/connection-pool');
Expand Down Expand Up @@ -375,3 +376,47 @@ describe('ConnectionPool', function () {
}, 4);
});
});

describe('Load Test', function() {
var statistics = require('simple-statistics');

it('Memory Leak Detection', function(done) {
this.timeout(60000);
if (!global.gc)
throw new Error('must run nodejs with --expose-gc');
var count = 0;
var mem = [];
var groupCount = 20;
var poolSize = 1000;
var max = poolSize * groupCount;

var pool = new ConnectionPool({ max: poolSize, min: poolSize, retryDelay: 1}, {
userName: 'testLogin',
password: 'wrongPassword',
server: 'localhost'
});

pool.on('error', function() {
if ((++count % poolSize) !== 0)
return;

global.gc();

var heapUsedKB = Math.round(process.memoryUsage().heapUsed / 1024);
mem.push([count, heapUsedKB]);

console.log(count + ': ' + heapUsedKB + 'KB');

if (count === max) {
var data = statistics.linearRegression(mem);
//console.log(data.m);
if (data.m >= 0.025)
done(new Error('Memory leak not detected.'));
else
done();

pool.drain();
}
});
});
});

0 comments on commit 5f602c4

Please sign in to comment.