Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case to demonstrate memory-leak
- Loading branch information
1 parent
6c6149a
commit cd153d0
Showing
2 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
var assert = require('assert') | ||
var Promise = require('../') | ||
|
||
var i = 0 | ||
var sampleA, sampleB | ||
|
||
function next() { | ||
return new Promise(function (resolve) { | ||
i++ | ||
/* | ||
if (i % 100000 === 0) { | ||
global.gc() | ||
console.dir(process.memoryUsage()) | ||
} | ||
*/ | ||
if (i === 100000 && typeof global.gc === 'function') { | ||
global.gc() | ||
sampleA = process.memoryUsage() | ||
} | ||
if (i > 100000 * 5) { | ||
if (typeof global.gc === 'function') { | ||
global.gc() | ||
sampleB = process.memoryUsage() | ||
console.dir(sampleA) | ||
console.dir(sampleB) | ||
assert(sampleA.rss * 1.2 > sampleB.rss, 'RSS should not grow by more than 20%') | ||
assert(sampleA.heapTotal * 1.2 > sampleB.heapTotal, 'heapTotal should not grow by more than 20%') | ||
assert(sampleA.heapUsed * 1.2 > sampleB.heapUsed, 'heapUsed should not grow by more than 20%') | ||
} | ||
} else { | ||
setImmediate(resolve) | ||
} | ||
}).then(next) | ||
} | ||
|
||
if (typeof global.gc !== 'function') { | ||
console.warn('You must run with --expose-gc to test for memory leak.') | ||
} | ||
next().done() |