diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-09-20 01:29:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-20 08:29:35 +0800 |
commit | ef3831437d830714178b7342a120ee6c8bf082c4 (patch) | |
tree | be28de366e7c07cca6d4b73e2afdcf14f303ff0a | |
parent | 171c5447052fe2be89219c1670420e04684b95fb (diff) | |
download | tracifyjs-ef3831437d830714178b7342a120ee6c8bf082c4.tar.gz tracifyjs-ef3831437d830714178b7342a120ee6c8bf082c4.zip |
improve `ufuzz` duty cycle heuristic (#4132)
-rw-r--r-- | test/ufuzz/actions.js | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/test/ufuzz/actions.js b/test/ufuzz/actions.js index fa4431a7..a5cd0eb2 100644 --- a/test/ufuzz/actions.js +++ b/test/ufuzz/actions.js @@ -4,46 +4,47 @@ var get = require("https").get; var parse = require("url").parse; var base = process.argv[2]; var token = process.argv[3]; - -function read(url, callback) { - var options = parse(url); - options.headers = { - "Authorization": "Token " + token, - "User-Agent": "UglifyJS", - }; - get(options, function(response) { - var chunks = []; - response.setEncoding("utf8"); - response.on("data", function(chunk) { - chunks.push(chunk); - }).on("end", function() { - callback(JSON.parse(chunks.join(""))); - }); - }); -} - var queued = 0, total = 0, earliest, now = Date.now(); process.on("beforeExit", function() { if (queued > 3) { process.stdout.write("0"); - } else if (now - earliest > 0 && total > 1) { - process.stdout.write(Math.min(20 * (now - earliest) / (total - 1), 18000000).toFixed(0)); } else { - process.stdout.write("3600000"); + var average = total > 2 && (now - earliest) / (total - 1); + process.stdout.write(Math.min(Math.max(20 * average, 2700000), 18000000).toFixed(0)); } }); read(base + "/actions/workflows/ufuzz.yml/runs?event=schedule", function(reply) { - reply.workflow_runs.filter(function(workflow) { + check(reply, "workflow_runs").filter(function(workflow) { return /^(in_progress|queued|)$/.test(workflow.status); }).forEach(function(workflow) { read(workflow.jobs_url, function(reply) { - reply.jobs.forEach(function(job) { + check(reply, "jobs").forEach(function(job) { if (job.status == "queued") queued++; total++; - if (!job.started_at) return; - var start = new Date(job.started_at); + var start = Date.parse(job.started_at); if (!(earliest < start)) earliest = start; }); }); }); }); + +function read(url, callback) { + var options = parse(url); + options.headers = { + "Authorization": "Token " + token, + "User-Agent": "UglifyJS", + }; + get(options, function(response) { + var chunks = []; + response.setEncoding("utf8"); + response.on("data", function(chunk) { + chunks.push(chunk); + }).on("end", function() { + callback(JSON.parse(chunks.join(""))); + }); + }); +} + +function check(reply, field) { + return reply && Array.isArray(reply[field]) ? reply[field] : []; +} |