Added dev reporting
This commit is contained in:
parent
d4acc497f1
commit
f559b653f2
10 changed files with 145 additions and 12 deletions
4
dev/suite/failing.js
Normal file
4
dev/suite/failing.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
export default function failingTest(){
|
||||
console.log("This came from a failing test!");
|
||||
return {status:1};
|
||||
}
|
4
dev/suite/primary.js
Normal file
4
dev/suite/primary.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
export default function primaryTest(){
|
||||
console.log("This came from a primary test!");
|
||||
return {status:0, pipelineData:"SomeData"};
|
||||
}
|
47
dev/suite/runner.js
Normal file
47
dev/suite/runner.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
import axios from "axios";
|
||||
import primary from "./primary.js";
|
||||
import secondary from "./secondary.js";
|
||||
import single from "./single.js";
|
||||
import failing from "./failing.js";
|
||||
|
||||
// Constants
|
||||
const endLiveCount = 2;
|
||||
const reportingUrl = `${process.env.QUALITEER_URL}/api/dev/rabbit/TestResults`;
|
||||
// Pull args
|
||||
const args = process.argv.slice(2);
|
||||
const test = (args.find((v)=>v.includes("test=")) ?? "").replace("test=","");
|
||||
const pipelineData = (args.find((v)=>v.includes("pipelineData=")) ?? "").replace("pipelineData=","");
|
||||
const pipelineLife = parseInt((args.find((v)=>v.includes("pipelineLife=")) ?? "0").replace("pipelineLife=",""));
|
||||
const pipelineDashboardSocket = (args.find((v)=>v.includes("pipelineDashboardSocket=")) ?? "").replace("pipelineDashboardSocket=","") || undefined;
|
||||
|
||||
const logNow = () => console.log(Date.now());
|
||||
const liveIndicator = () => {
|
||||
for (var i = 0; i < endLiveCount; i++) setTimeout(logNow, i * 1000);
|
||||
}
|
||||
|
||||
const runTests = () => {
|
||||
switch (test) {
|
||||
case "primary":
|
||||
return primary();
|
||||
case "secondary":
|
||||
return secondary(pipelineData);
|
||||
case "single":
|
||||
return single();
|
||||
case "failing":
|
||||
return failing();
|
||||
default:
|
||||
return single();
|
||||
}
|
||||
}
|
||||
|
||||
// Run
|
||||
liveIndicator();
|
||||
setTimeout(()=>{
|
||||
const status = runTests();
|
||||
const testResult = {...status, name:test, pipelineLife, pipelineDashboardSocket}
|
||||
axios.post(reportingUrl, {testResult}).catch((e)=>{console.log(e.response.status)});
|
||||
},endLiveCount * 1000);
|
||||
|
||||
|
||||
|
||||
|
4
dev/suite/secondary.js
Normal file
4
dev/suite/secondary.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
export default function secondaryTest(pipelineData){
|
||||
console.log("This came from a secondary test!");
|
||||
return {status: + (pipelineData !== "SomeData")};
|
||||
}
|
4
dev/suite/single.js
Normal file
4
dev/suite/single.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
export default function singleTest(){
|
||||
console.log("This came from a single test!");
|
||||
return {status:0};
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
import { v4 } from "uuid";
|
||||
import applyJob from "./kubernetes.js";
|
||||
import buildJob from "./job-builder.js";
|
||||
|
||||
const maxJobs = process.env.MAX_JOBS ? parseInt(process.env.MAX_JOBS) : 3;
|
||||
|
||||
|
@ -41,7 +42,8 @@ class JobManager {
|
|||
this.clientMaxJobs
|
||||
)
|
||||
throw Error("Client's Active Jobs Exceeded!");
|
||||
const job = { ...jobRequest };
|
||||
|
||||
const job = buildJob(jobRequest, id);
|
||||
job.id = v4();
|
||||
job.log = [];
|
||||
this.clients[id].jobs.push(job);
|
||||
|
|
59
lib/core/job-builder.js
Normal file
59
lib/core/job-builder.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
const baseCommand = "node";
|
||||
const suiteEntry = "dev/suite/runner.js";
|
||||
const pipelineMapping = [
|
||||
{
|
||||
id: 0,
|
||||
pipeline: [{ name: "primary" }, { name: "secondary", delay: 5000 }],
|
||||
},
|
||||
];
|
||||
|
||||
const buildCommon = (jobRequest) => {
|
||||
const { testName } = jobRequest;
|
||||
if (!testName) throw Error("'testName' must be provided!");
|
||||
const command = [baseCommand, suiteEntry, `test=${testName}`];
|
||||
|
||||
// Apply Common Flags
|
||||
command.push("isRetry=false");
|
||||
|
||||
// Return new request
|
||||
return { ...jobRequest, command };
|
||||
};
|
||||
|
||||
const buildSingle = (jobReq) => jobReq;
|
||||
|
||||
const buildMarker = (jobReq) => {};
|
||||
|
||||
const buildProject = (jobReq) => {};
|
||||
|
||||
const pipelineMaxLife = (testName) => {
|
||||
const pipelines = pipelineMapping
|
||||
.filter((m) => m.pipeline.find((t) => t.name === testName))
|
||||
.map((m) => m.pipeline);
|
||||
return Math.max(pipelines.map((p) => p.length)) + 1;
|
||||
};
|
||||
|
||||
const buildCompound = (jobReq, socketId) => {
|
||||
const { testName, command } = jobReq;
|
||||
const pipelineLife = jobReq.pipelineLife ?? pipelineMaxLife(testName);
|
||||
command.push(`pipelineLife=${pipelineLife}`);
|
||||
command.push(`pipelineDashboardSocket=${socketId}`);
|
||||
return { ...jobReq, command };
|
||||
};
|
||||
|
||||
const nextCompound = (previousTest) => {};
|
||||
|
||||
export default function jobBuilder(jobRequest, id) {
|
||||
const jobReq = buildCommon(jobRequest, id);
|
||||
switch (jobRequest.type) {
|
||||
case "single":
|
||||
return buildSingle(jobReq);
|
||||
case "marker":
|
||||
return buildMarker(jobReq);
|
||||
case "project":
|
||||
return buildProject(jobReq);
|
||||
case "compound":
|
||||
return buildCompound(jobReq, id);
|
||||
default:
|
||||
throw Error("No Job Request Type Specified!");
|
||||
}
|
||||
}
|
|
@ -9,11 +9,12 @@ import catalog from "../routes/catalog-route.js";
|
|||
import jobs from "../routes/jobs-route.js";
|
||||
|
||||
import mock from "../routes/mock-route.js";
|
||||
|
||||
import dev from "../routes/dev-route.js";
|
||||
const app = express();
|
||||
// Special Routes
|
||||
app.all("/", (req, res) => res.redirect("/qualiteer"));
|
||||
if (process.env.MOCK_ROUTES === "true") app.use(mock);
|
||||
if(process.env.USE_DEV_ROUTER === "true") app.use("/api/dev",dev);
|
||||
|
||||
// Middlewares
|
||||
|
||||
|
|
14
lib/routes/dev-route.js
Normal file
14
lib/routes/dev-route.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { Router, json as jsonMiddleware } from "express";
|
||||
import TestResultsWorker from "../rabbit/workers/TestResultsWorker.js";
|
||||
|
||||
const testResultsHandler = new TestResultsWorker();
|
||||
|
||||
const router = Router();
|
||||
router.use(jsonMiddleware());
|
||||
router.post("/rabbit/TestResults", (req, res) => {
|
||||
const { testResult } = req.body;
|
||||
testResultsHandler.onMessage(testResult);
|
||||
res.sendStatus(200);
|
||||
});
|
||||
|
||||
export default router;
|
|
@ -7,22 +7,16 @@ import { Initiator, Executor } from "qualiteer/clients";
|
|||
const qltr = new Qualiteer();
|
||||
await qltr.start();
|
||||
|
||||
const url = "https://Qualiteer.elijahparker3.repl.co";
|
||||
const url = process.env.QUALITEER_URL;
|
||||
|
||||
// Create an initiator and make a job request
|
||||
const primary = new Initiator(url);
|
||||
const job = {
|
||||
command: ["node", "dev/other.js"],
|
||||
type: "compound",
|
||||
testName: "primary",
|
||||
pipelineLife: 1,
|
||||
name: "testing",
|
||||
image: "node",
|
||||
};
|
||||
await primary.newJob(job, null, () => console.log("Primary Job Concluded"));
|
||||
|
||||
/*const { clients } = qltr.jobs;
|
||||
const skId = Object.keys(clients)[0];
|
||||
const { jobs } = clients[skId];
|
||||
const serverJob = jobs[0];
|
||||
|
||||
const exec = new Executor(url, serverJob);
|
||||
exec.runJob();
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue