improve test/travis-ufuzz.js (#2795)

- print usage
- support concurrent jobs
- improve instance utilisation
- resume after V8 self-destruct
This commit is contained in:
Alex Lam S.L
2018-01-16 17:33:21 +08:00
committed by GitHub
parent b4aef753e7
commit 7857354d85

View File

@@ -1,22 +1,29 @@
"use strict"; "use strict";
var child_process = require("child_process");
var https = require("https");
var url = require("url");
var period = 45 * 60 * 1000; var period = 45 * 60 * 1000;
var wait = 2 * 60 * 1000; var wait = 2 * 60 * 1000;
var ping = 5 * 60 * 1000; var ping = 5 * 60 * 1000;
if (process.argv.length > 2) { if (process.argv[2] == "run") {
for (var i = 0; i < 2; i++) spawn();
} else if (process.argv.length > 2) {
var token = process.argv[2]; var token = process.argv[2];
var branch = process.argv[3] || "v" + require("../package.json").version; var branch = process.argv[3] || "v" + require("../package.json").version;
var project = encodeURIComponent(process.argv[4] || "mishoo/UglifyJS2"); var repository = encodeURIComponent(process.argv[4] || "mishoo/UglifyJS2");
(function init() { var concurrency = process.argv[5] || 1;
setTimeout(init, period + wait); (function request() {
var options = require("url").parse("https://api.travis-ci.org/repo/" + project + "/requests"); setTimeout(request, (period + wait) / concurrency);
var options = url.parse("https://api.travis-ci.org/repo/" + repository + "/requests");
options.method = "POST"; options.method = "POST";
options.headers = { options.headers = {
"Content-Type": "application/json", "Content-Type": "application/json",
"Travis-API-Version": 3, "Travis-API-Version": 3,
"Authorization": "token " + token "Authorization": "token " + token
}; };
require("https").request(options, function(res) { https.request(options, function(res) {
console.log("HTTP", res.statusCode); console.log("HTTP", res.statusCode);
console.log(JSON.stringify(res.headers, null, 2)); console.log(JSON.stringify(res.headers, null, 2));
console.log(); console.log();
@@ -31,22 +38,22 @@ if (process.argv.length > 2) {
language: "node_js", language: "node_js",
node_js: "9", node_js: "9",
sudo: false, sudo: false,
script: "node test/travis-ufuzz" script: "node test/travis-ufuzz run"
} }
} }
})); }));
})(); })();
} else { } else {
var child = require("child_process").spawn("node", [ console.log("Usage: test/travis-ufuzz.js <token> [branch] [repository] [concurrency]");
}
function spawn() {
var child = child_process.spawn("node", [
"--max-old-space-size=2048", "--max-old-space-size=2048",
"test/ufuzz" "test/ufuzz"
], { ], {
stdio: [ "ignore", "pipe", "pipe" ] stdio: [ "ignore", "pipe", "pipe" ]
}).on("exit", function() { }).on("exit", respawn);
console.log(line);
clearInterval(keepAlive);
clearTimeout(timer);
});
var line = ""; var line = "";
child.stdout.on("data", function(data) { child.stdout.on("data", function(data) {
line += data; line += data;
@@ -61,7 +68,14 @@ if (process.argv.length > 2) {
}, ping); }, ping);
var timer = setTimeout(function() { var timer = setTimeout(function() {
clearInterval(keepAlive); clearInterval(keepAlive);
child.removeAllListeners("exit"); child.removeListener("exit", respawn);
child.kill(); child.kill();
}, period); }, period);
function respawn() {
console.log(line);
clearInterval(keepAlive);
clearTimeout(timer);
spawn();
}
} }