File tree Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change 4
4
"description" : " Bare bones Promises/A+ implementation" ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
7
- "test" : " mocha --timeout 200 --slow 99999" ,
7
+ "test" : " mocha --timeout 200 --slow 99999 && npm run test-memory-leak " ,
8
8
"test-resolve" : " mocha test/resolver-tests.js -R spec --timeout 200 --slow 999999" ,
9
- "test-extensions" : " mocha test/extensions-tests.js -R spec --timeout 200 --slow 999999"
9
+ "test-extensions" : " mocha test/extensions-tests.js -R spec --timeout 200 --slow 999999" ,
10
+ "test-memory-leak" : " node --expose-gc test/memory-leak.js"
10
11
},
11
12
"repository" : {
12
13
"type" : " git" ,
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ var assert = require ( 'assert' )
4
+ var Promise = require ( '../' )
5
+
6
+ var i = 0
7
+ var sampleA , sampleB
8
+
9
+ function next ( ) {
10
+ return new Promise ( function ( resolve ) {
11
+ i ++
12
+ /*
13
+ if (i % 100000 === 0) {
14
+ global.gc()
15
+ console.dir(process.memoryUsage())
16
+ }
17
+ */
18
+ if ( i === 100000 && typeof global . gc === 'function' ) {
19
+ global . gc ( )
20
+ sampleA = process . memoryUsage ( )
21
+ }
22
+ if ( i > 100000 * 5 ) {
23
+ if ( typeof global . gc === 'function' ) {
24
+ global . gc ( )
25
+ sampleB = process . memoryUsage ( )
26
+ console . dir ( sampleA )
27
+ console . dir ( sampleB )
28
+ assert ( sampleA . rss * 1.2 > sampleB . rss , 'RSS should not grow by more than 20%' )
29
+ assert ( sampleA . heapTotal * 1.2 > sampleB . heapTotal , 'heapTotal should not grow by more than 20%' )
30
+ assert ( sampleA . heapUsed * 1.2 > sampleB . heapUsed , 'heapUsed should not grow by more than 20%' )
31
+ }
32
+ } else {
33
+ setImmediate ( resolve )
34
+ }
35
+ } ) . then ( next )
36
+ }
37
+
38
+ if ( typeof global . gc !== 'function' ) {
39
+ console . warn ( 'You must run with --expose-gc to test for memory leak.' )
40
+ }
41
+ next ( ) . done ( )
You can’t perform that action at this time.
0 commit comments