From 42b3246eb8debb60a91864b90129f516c9b91ddb Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Tue, 16 Jan 2018 14:56:38 +0800 Subject: [PATCH] improve `test/travis-ufuzz.js` - print usage - support concurrent jobs - improve instance utilisation --- test/travis-ufuzz.js | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/test/travis-ufuzz.js b/test/travis-ufuzz.js index 579b7448..c4f918ad 100644 --- a/test/travis-ufuzz.js +++ b/test/travis-ufuzz.js @@ -3,13 +3,16 @@ var period = 45 * 60 * 1000; var wait = 2 * 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 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"); + var concurrency = process.argv[5] || 1; (function init() { - setTimeout(init, period + wait); - var options = require("url").parse("https://api.travis-ci.org/repo/" + project + "/requests"); + setTimeout(init, (period + wait) / concurrency); + var options = require("url").parse("https://api.travis-ci.org/repo/" + repository + "/requests"); options.method = "POST"; options.headers = { "Content-Type": "application/json", @@ -31,22 +34,22 @@ if (process.argv.length > 2) { language: "node_js", node_js: "9", sudo: false, - script: "node test/travis-ufuzz" + script: "node test/travis-ufuzz run" } } })); })(); } else { + console.log("Usage: test/travis-ufuzz.js [branch] [repository] [concurrency]"); +} + +function spawn() { var child = require("child_process").spawn("node", [ "--max-old-space-size=2048", "test/ufuzz" ], { stdio: [ "ignore", "pipe", "pipe" ] - }).on("exit", function() { - console.log(line); - clearInterval(keepAlive); - clearTimeout(timer); - }); + }).on("exit", respawn); var line = ""; child.stdout.on("data", function(data) { line += data; @@ -61,7 +64,14 @@ if (process.argv.length > 2) { }, ping); var timer = setTimeout(function() { clearInterval(keepAlive); - child.removeAllListeners("exit"); + child.removeListener("exit", respawn); child.kill(); }, period); + + function respawn() { + console.log(line); + clearInterval(keepAlive); + clearTimeout(timer); + spawn(); + } }