qualiteer/lib/server/rabbit/workers/TestResultsWorker.js
dunemask ba8e6ded26 Initial loading of AutoPipeline (#6)
Co-authored-by: Dunemask <dunemask@gmail.com>
Reviewed-on: https://gitea.dunemask.net/elysium/qualiteer/pulls/6
2023-08-15 13:18:05 +00:00

64 lines
1.9 KiB
JavaScript

// Imports
import { Worker } from "rabbiteer";
import { VERB } from "../../util/logging.js";
import { getPipelineMappings } from "../../database/queries/catalog.js";
import { insertTestResult } from "../../database/queries/results.js";
import evt from "../../../common/sockets/events.js";
import { asTree, asBranches, as1d } from "../../../../src/util/pipelines.js";
// Class
export default class TestResultsWorker extends Worker {
constructor(skio) {
super("TestResults");
this.skio = skio;
}
/* Example Test Result
{
testName: “SomeTest”,
testClass: “SomeClass”,
testMethod: “SomeMethod”,
testType: “API/UI”,
testTimestamp: 123893024,
origin: “TestSuite”,
failed: true,
failedMessage: “Some Failure”,
screenshotUrl: “https://screenshot”,
expectedScreenshotUrl: “https://expected”
consoleLogUrl: “https://consolelog”
}
*/
async onMessage(testResult) {
const { pipeline, autoPipeline } = testResult;
await this.handleReporting(testResult);
if(autoPipeline) return this.autoPipeline(testResult);
// Alter to start next test
// TODO the delay should be autopopulated either by the suite, or filled in by the server
if (pipeline) return this.pipelineTrigger(pipeline);
}
pipelineTrigger(pipeline) {
const { dashboardSocketId: dsi } = pipeline;
this.skio.to(dsi).emit(evt.PPL_TRG, pipeline);
}
async autoPipeline(testResult){
const {name} = testResult;
console.log(testResult);
const mappings = await getPipelineMappings();
const primaries = mappings.filter((m) =>
m.find((t) => t.name === name)
);
const pipelineTree = asTree(primaries);
const pipelineReq = pipelineTree[name];
delete pipelineReq.__testDelay;
for(var k of Object.keys(pipelineReq)){
console.log("Would auto start: ", k);
}
}
handleReporting(result) {
VERB("TestResults", result.name);
insertTestResult(result);
}
}