Skip to content

Commit

Permalink
Use child processes to run each set of tests, in order to deal with t…
Browse files Browse the repository at this point in the history
…he memory leak in vm.runInNewContext()
  • Loading branch information
Golmote committed Oct 26, 2015
1 parent e8a31a5 commit 9a4b6fa
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
17 changes: 17 additions & 0 deletions tests/run-child.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

var TestCase = require("./helper/test-case");
var argv = require("yargs").argv;

if (argv.language) {
process.on('message', function (data) {
if (data.filePath) {
try {
TestCase.runTestCase(argv.language, data.filePath);
process.send({success: true});
} catch (e) {
process.send({error: e});
}
}
});
}
44 changes: 36 additions & 8 deletions tests/run.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";

var TestDiscovery = require("./helper/test-discovery");
var TestCase = require("./helper/test-case");
var path = require("path");
var argv = require("yargs").argv;
var child_process = require("child_process");

var testSuite;
if (argv.language) {
Expand All @@ -23,17 +23,45 @@ for (var language in testSuite) {
describe("Testing language '" + language + "'", function () {
this.timeout(10000);

// Each set of tests runs in its own child process
var child;
before(function () {
child = child_process.fork(__dirname + "/run-child.js", ['--language=' + language], {
stdio: 'inherit'
});
});

after(function () {
child.kill();
});

testFiles.forEach(
function (filePath) {
var fileName = path.basename(filePath, path.extname(filePath));
var fileName = path.basename(filePath, path.extname(filePath));

it("– should pass test case '" + fileName + "'",
function () {
TestCase.runTestCase(language, filePath);
}
);
it("– should pass test case '" + fileName + "'",
function (done) {

child.removeAllListeners('message');
child.on('message', function (o) {
// We have to delay the call,
// otherwise the first message is received
// over and over again.
setTimeout(function() {
if (o.error) {
throw o.error;
} else if (o.success) {
done();
}
}, 1);
});
child.send({
filePath: filePath
});
}
);
}
);
});
})(language, testSuite[language]);
}
}

0 comments on commit 9a4b6fa

Please sign in to comment.