Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unbounded memory use in tests #5166

Merged
merged 2 commits into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jobs:
docker:
- image: mbgl/ci:r4-linux-gl-js
working_directory: ~/mapbox-gl-js
resource_class: large
steps:
- checkout
- restore_cache:
Expand All @@ -47,7 +46,6 @@ jobs:
docker:
- image: mbgl/ci:r4-linux-gl-js
working_directory: ~/mapbox-gl-js
resource_class: large
steps:
- checkout
- restore_cache:
Expand Down
4 changes: 2 additions & 2 deletions src/util/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function restore(): Window {
};

window.useFakeHTMLCanvasGetContext = function() {
this.HTMLCanvasElement.prototype.getContext = sinon.stub().returns('2d');
this.HTMLCanvasElement.prototype.getContext = function() { return '2d'; };
};

window.useFakeXMLHttpRequest = function() {
Expand All @@ -55,7 +55,7 @@ function restore(): Window {

window.restore = restore;

window.ImageData = window.ImageData || sinon.stub().returns(false);
window.ImageData = window.ImageData || function() { return false; };

util.extend(module.exports, window);

Expand Down
21 changes: 10 additions & 11 deletions test/suite_implementation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const ajax = require('../src/util/ajax');
const sinon = require('sinon');
const request = require('request');
const PNG = require('pngjs').PNG;
const Map = require('../src/ui/map');
Expand Down Expand Up @@ -126,7 +125,7 @@ function cached(data, callback) {
});
}

sinon.stub(ajax, 'getJSON').callsFake(({ url }, callback) => {
ajax.getJSON = function({ url }, callback) {
if (cache[url]) return cached(cache[url], callback);
return request(url, (error, response, body) => {
if (!error && response.statusCode >= 200 && response.statusCode < 300) {
Expand All @@ -142,9 +141,9 @@ sinon.stub(ajax, 'getJSON').callsFake(({ url }, callback) => {
callback(error || new Error(response.statusCode));
}
});
});
};

sinon.stub(ajax, 'getArrayBuffer').callsFake(({ url }, callback) => {
ajax.getArrayBuffer = function({ url }, callback) {
if (cache[url]) return cached(cache[url], callback);
return request({ url, encoding: null }, (error, response, body) => {
if (!error && response.statusCode >= 200 && response.statusCode < 300) {
Expand All @@ -154,9 +153,9 @@ sinon.stub(ajax, 'getArrayBuffer').callsFake(({ url }, callback) => {
callback(error || new Error(response.statusCode));
}
});
});
};

sinon.stub(ajax, 'getImage').callsFake(({ url }, callback) => {
ajax.getImage = function({ url }, callback) {
if (cache[url]) return cached(cache[url], callback);
return request({ url, encoding: null }, (error, response, body) => {
if (!error && response.statusCode >= 200 && response.statusCode < 300) {
Expand All @@ -169,15 +168,15 @@ sinon.stub(ajax, 'getImage').callsFake(({ url }, callback) => {
callback(error || new Error(response.statusCode));
}
});
});
};

sinon.stub(browser, 'getImageData').callsFake((img) => {
browser.getImageData = function(img) {
return new Uint8Array(img.data);
});
};

// Hack: since node doesn't have any good video codec modules, just grab a png with
// the first frame and fake the video API.
sinon.stub(ajax, 'getVideo').callsFake((urls, callback) => {
ajax.getVideo = function(urls, callback) {
return request({ url: urls[0], encoding: null }, (error, response, body) => {
if (!error && response.statusCode >= 200 && response.statusCode < 300) {
new PNG().parse(body, (err, png) => {
Expand All @@ -195,4 +194,4 @@ sinon.stub(ajax, 'getVideo').callsFake((urls, callback) => {
callback(error || new Error(response.statusCode));
}
});
});
};