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

Run memory leak test on all systems #3887

Merged
merged 5 commits into from Nov 29, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 48 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Expand Up @@ -33,9 +33,8 @@
"test": "npm run test:all",
"test:all": "npm run test:only && npm run test:typescript && npm run test:leak && npm run test:package",
"test:coverage": "nyc --reporter html mocha",
"test:leak": "cross-os test:leak:os",
"test:leak": "node --expose-gc test/leak/index.js",
"test:package": "node scripts/test-package.js",
"test:leak:nix": "npm i --silent --no-save weak@1 && node --expose-gc test/leak/index.js",
"test:only": "mocha",
"test:quick": "mocha -b",
"test:typescript": "tsc --noEmit -p test/typescript && tsc --noEmit",
Expand Down Expand Up @@ -81,7 +80,6 @@
"codecov": "^3.7.2",
"colorette": "^1.2.1",
"core-js": "^3.6.5",
"cross-os": "^1.3.0",
"date-time": "^3.1.0",
"es5-shim": "^4.5.14",
"es6-shim": "^0.35.5",
Expand Down Expand Up @@ -124,6 +122,7 @@
"tslint": "^6.1.3",
"typescript": "^4.0.3",
"url-parse": "^1.4.7",
"weak-napi": "^2.0.2",
"yargs-parser": "^20.2.1"
},
"files": [
Expand Down
44 changes: 27 additions & 17 deletions test/leak/index.js
@@ -1,6 +1,6 @@
const path = require('path');
const rollup = require('../..');
const weak = require('weak');
const weak = require('weak-napi');

var shouldCollect = false;
var isCollected = false;
Expand All @@ -9,28 +9,38 @@ function onCollect() {
isCollected = true;
}

const wait = () => new Promise(resolve => setTimeout(resolve));

async function waitForGC() {
const startTime = process.hrtime();
do {
global.gc();
await wait();
} while (!isCollected && process.hrtime(startTime)[0] < 3);
}

var cache;
function run() {
return rollup
.rollup({
input: path.resolve(__dirname, 'main.js'),
cache
})
.then(bundle => {
weak(bundle, onCollect);
cache = bundle;
global.gc();
if (shouldCollect && !isCollected) {
throw new Error('Memory leak detected');
}
shouldCollect = true;
});
async function run() {
const bundle = await rollup.rollup({
input: path.resolve(__dirname, 'main.js'),
cache
});
weak(bundle, onCollect);
cache = bundle;
if (shouldCollect) {
await waitForGC();
if (!isCollected) {
throw new Error('Memory leak detected');
}
}
shouldCollect = true;
}

run()
.then(run)
.then(() => {
console.log('Success: No memory leak detected');
console.log('Success: Previous bundle was correctly garbage collected.');
process.exit(0);
})
.catch(err => {
console.error(err.message);
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
@@ -1,7 +1,7 @@
require('source-map-support').install();

describe('rollup', function () {
this.timeout(10000);
this.timeout(15000);
require('./misc/index.js');
require('./function/index.js');
require('./form/index.js');
Expand Down