summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--package.json1
-rw-r--r--platform/node/test/memory.test.js (renamed from platform/node/test/js/memory.test.js)26
3 files changed, 16 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index 165dbb8cce..4b10a77233 100644
--- a/Makefile
+++ b/Makefile
@@ -222,6 +222,7 @@ xnode: $(NODE_OUTPUT_PATH)/config.gypi $(GYP_DEPENDENCIES)
.PHONY: test-node
test-node: node
npm test
+ npm run test-memory
npm run test-suite
#### Qt targets #####################################################
diff --git a/package.json b/package.json
index 39b83283d5..2d216cca08 100644
--- a/package.json
+++ b/package.json
@@ -35,6 +35,7 @@
"preinstall": "npm install node-pre-gyp",
"install": "node-pre-gyp install --fallback-to-build=false || make node",
"test": "tape platform/node/test/js/**/*.test.js",
+ "test-memory": "node --expose-gc platform/node/test/memory.test.js",
"test-suite": "node platform/node/test/render.test.js && node platform/node/test/query.test.js"
},
"gypfile": true,
diff --git a/platform/node/test/js/memory.test.js b/platform/node/test/memory.test.js
index 536342a649..e958f8a29b 100644
--- a/platform/node/test/js/memory.test.js
+++ b/platform/node/test/memory.test.js
@@ -1,16 +1,15 @@
'use strict';
var fs = require('fs');
-var mbgl = require('../../../../lib/mapbox-gl-native');
+var mbgl = require('../../../lib/mapbox-gl-native');
var path = require('path');
var test = require('tape');
var testParams = {
mapPoolSize: 10,
- numRenderings: 30,
- heapGrowthThreshould: 256 * 1024, // 256 KB
-
- ratio: 2,
+ numRenderings: 100,
+ heapGrowthThreshold: 0,
+ ratio: 2
};
function readFixture(file) {
@@ -28,6 +27,11 @@ var tile_raster = readFixture('raster.tile');
var tile_vector = readFixture('vector.tile');
test('Memory', function(t) {
+ // Trigger garbage collection before starting test, then initialize
+ // heap size
+ if (typeof gc === 'function') gc();
+ var lastHeapSize = process.memoryUsage()['heapUsed'];
+
var options = {
request: function(req, callback) {
if (req.url == null) {
@@ -40,7 +44,7 @@ test('Memory', function(t) {
callback(null, { data: glyph });
} else if (req.url.endsWith('mapbox.satellite')) {
callback(null, { data: source_raster });
- } else if (req.url.indexOf('satellite') > -1 && req.url.endsWith('png')) {
+ } else if (req.url.indexOf('satellite') > -1 && (req.url.endsWith('png') || req.url.endsWith('webp'))) {
callback(null, { data: tile_raster });
} else if (req.url.endsWith('mapbox.mapbox-streets-v7')) {
callback(null, { data: source_vector });
@@ -62,7 +66,6 @@ test('Memory', function(t) {
var renderCount = 0;
var heapGrowth = 0;
- var lastHeapSize = 0;
var interval = setInterval(function () {
if (mapPool.length == 0) {
@@ -81,22 +84,21 @@ test('Memory', function(t) {
mapPool.push(map);
if (renderCount % (testParams.numRenderings / 10) == 0) {
+ // Manually trigger garbage collection
+ if (typeof gc === 'function') gc();
+
var currentHeapSize = process.memoryUsage()['heapUsed'];
// Print some progress, so slow build bots don't timeout.
t.comment("Rendering (" + renderCount.toString() +
"/" + testParams.numRenderings.toString() + ")");
- if (lastHeapSize == 0) {
- lastHeapSize = currentHeapSize;
- }
-
heapGrowth = heapGrowth + currentHeapSize - lastHeapSize;
lastHeapSize = currentHeapSize;
}
if (++renderCount == testParams.numRenderings) {
- t.ok(heapGrowth < testParams.heapGrowthThreshould, heapGrowth);
+ t.ok(heapGrowth < testParams.heapGrowthThreshold, heapGrowth);
t.end();
clearInterval(interval);