improve `ufuzz` duty cycle heuristic (#4057)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 19 Aug 2020 15:29:01 +0000 (16:29 +0100)
committerGitHub <noreply@github.com>
Wed, 19 Aug 2020 15:29:01 +0000 (23:29 +0800)
test/ufuzz/actions.js

index 53754a7..f9567d5 100644 (file)
@@ -22,15 +22,14 @@ function read(url, callback) {
     });
 }
 
-var queued = 0, total = 0;
-var earliest, latest;
+var queued = 0, total = 0, earliest, now = Date.now();
 process.on("beforeExit", function() {
     if (queued > 3) {
         process.stdout.write("0");
-    } else if (total < 2) {
-        process.stdout.write("3600000");
+    } else if (now - earliest > 0 && total > 1) {
+        process.stdout.write(Math.min(20 * (now - earliest) / (total - 1), 6300000).toFixed(0));
     } else {
-        process.stdout.write(Math.min(20 * (latest - earliest) / (total - 1), 5400000).toFixed(0));
+        process.stdout.write("3600000");
     }
 });
 read(base + "/actions/workflows/ufuzz.yml/runs?event=schedule", function(reply) {
@@ -41,9 +40,9 @@ read(base + "/actions/workflows/ufuzz.yml/runs?event=schedule", function(reply)
             reply.jobs.forEach(function(job) {
                 if (job.status == "queued") queued++;
                 total++;
+                if (!job.started_at) return;
                 var start = new Date(job.started_at);
                 if (!(earliest < start)) earliest = start;
-                if (!(latest > start)) latest = start;
             });
         });
     });