Commit 07fa4ad9 authored by Renato Figueiro Maia's avatar Renato Figueiro Maia
Browse files

Teste de relatório de jobs terminados ao reconectar.

[SOMA-6857][SOMA-7166][SOMA-6693]
parent b4c5a409
Pipeline #70718 passed with stage
in 1 minute and 38 seconds
...@@ -108,69 +108,78 @@ describe("Registering SGA", function () { ...@@ -108,69 +108,78 @@ describe("Registering SGA", function () {
const [exitVal] = await sga.terminated(); const [exitVal] = await sga.terminated();
expect(exitVal).toEqual(0); expect(exitVal).toEqual(0);
}); });
});
it("should receive requests to execute and inform its completion", async () => { describe("Mocked SGA", function () {
const jobBody = utils.fillJobBody(); let config;
const driverMockup = { let regMockup;
execute_command: ` let sga;
expect(job.cmd_id == ${JSON.stringify(jobBody.cmd_id)})
expect(cmd_string == ${JSON.stringify(jobBody.cmd_string)}) const jobBody = utils.fillJobBody();
expect(user_token == ${JSON.stringify( const driverMockup = {
jobBody.parameters.csbase_command_user_token execute_command: `
)}) expect(job.cmd_id == ${JSON.stringify(jobBody.cmd_id)})
expect(not self.jobDataRef) expect(cmd_string == ${JSON.stringify(jobBody.cmd_string)})
self.jobDataRef = job.data expect(user_token == ${JSON.stringify(
job.data.start = now() jobBody.parameters.csbase_command_user_token
return true )})
`, expect(not self.jobDataRef)
is_command_done: ` self.jobDataRef = job.data
expect(self.jobDataRef == job.data) job.data.start = now()
if not job.data.start or now()-job.data.start < 0.1 then return true
return false `,
end is_command_done: `
job.data.start = false expect(self.jobDataRef == job.data)
return true, 0.07, 0.03, 0.01 if not job.data.start or now()-job.data.start < 0.1 then
`, return false
cleanup_job: ` end
expect(self.jobDataRef == job.data) job.data.start = false
expect(not self.jobCleanup) return true, 0.07, 0.03, 0.01
self.jobCleanup = true `,
`, cleanup_job: `
"actions.status": ` expect(self.jobDataRef == job.data)
expect(self.jobDataRef == job.data) expect(not self.jobCleanup)
expect(action == "status") self.jobCleanup = true
return true, { `,
someStatus = "some status", "actions.status": `
otherStatus = "other status", expect(self.jobDataRef == job.data)
anotherStatus = "another status", expect(action == "status")
nestedStatus = { return true, {
someNestedStatus = "some nested status", someStatus = "some status",
otherNestedStatus = "other nested status", otherStatus = "other status",
anotherNestedStatus = "another nested status", anotherStatus = "another status",
} nestedStatus = {
someNestedStatus = "some nested status",
otherNestedStatus = "other nested status",
anotherNestedStatus = "another nested status",
} }
`, }
}; `,
};
async function checkStatus(url) {
const statRes = await chakram.get(url);
chakram.expect(statRes).to.have.status(200);
chakram.expect(statRes).to.comprise.of.json({
someStatus: "some status",
otherStatus: "other status",
anotherStatus: "another status",
nestedStatus: {
someNestedStatus: "some nested status",
otherNestedStatus: "other nested status",
anotherNestedStatus: "another nested status",
},
});
}
const config = utils.fillSgaConfig(); afterEach(utils.clearAllResources);
const regMockup = new utils.RegistryService(config); beforeEach(() => {
const sga = new utils.SgaDaemon(config, driverMockup); config = utils.fillSgaConfig();
regMockup = new utils.RegistryService(config);
sga = new utils.SgaDaemon(config, driverMockup);
});
async function checkStatus(url) {
const statRes = await chakram.get(url);
chakram.expect(statRes).to.have.status(200);
chakram.expect(statRes).to.comprise.of.json({
someStatus: "some status",
otherStatus: "other status",
anotherStatus: "another status",
nestedStatus: {
someNestedStatus: "some nested status",
otherNestedStatus: "other nested status",
anotherNestedStatus: "another nested status",
},
});
}
it("should receive requests to execute and inform its completion", async () => {
spyOn(regMockup, "heartbeat").and.callThrough(); spyOn(regMockup, "heartbeat").and.callThrough();
spyOn(regMockup, "status").and.callThrough(); spyOn(regMockup, "status").and.callThrough();
...@@ -198,6 +207,52 @@ describe("Registering SGA", function () { ...@@ -198,6 +207,52 @@ describe("Registering SGA", function () {
await checkStatus(execRes.body.actions.status); await checkStatus(execRes.body.actions.status);
}); });
it("should report jobs completed on registration", async () => {
function notFound(req, res) {
res.status(404).end();
}
await regMockup.start();
await sga.start();
const [regReq1] = await events.once(regMockup.events, "register");
utils.checkRegistration(regReq1, config);
const registerSpy = spyOn(regMockup, "register");
const heartbeatSpy = spyOn(regMockup, "heartbeat");
const statusSpy = spyOn(regMockup, "status");
const completionSpy = spyOn(regMockup, "completion");
registerSpy.and.callFake(notFound);
  • Não entendi o porquê todas dessas funções retornarem 404. É para simular um servidor inacessível? Mas logo em seguida esse servidor submete um job.

    Edited by Felipe Pina
  • Não entendi o porquê todas dessas funções retornarem 404. É para simular um servidor inacessível?

    Exato. É para isso mesmo, pois não encontrei formar de desligar temporariamente o servidor mockado com o 'express.js'.

    Mas logo em seguida esse servidor submete um job.

    Sim, pois o cenário do teste é validar que o SGA informará um job que termine enquanto o servidor está incessível.

    Edited by Renato Figueiro Maia
Please register or sign in to reply
heartbeatSpy.and.callFake(notFound);
statusSpy.and.callFake(notFound);
completionSpy.and.callFake(notFound);
const execRes = await chakram.post(regReq1.body.actions.job, jobBody);
chakram.expect(execRes).to.have.status(201);
await utils.waitMsec(200); // time for job to complete
registerSpy.and.callThrough();
const [regReq2] = await events.once(regMockup.events, "register");
utils.checkRegistration(regReq2, config);
heartbeatSpy.and.callThrough();
statusSpy.and.callThrough();
completionSpy.and.callThrough();
expect(regReq2.body.persistent_data.lost).toEqual(
jasmine.objectContaining({})
);
const retrievedJob = regReq2.body.persistent_data.retrieved[0];
expect(retrievedJob.cmd_id).toEqual(jobBody.cmd_id);
expect(retrievedJob.actions).toEqual(
jasmine.objectContaining(execRes.body.actions)
);
await checkStatus(execRes.body.actions.status);
});
}); });
describe("Registered SGA", function () { describe("Registered SGA", function () {
......
...@@ -169,7 +169,6 @@ class SgaDaemon { ...@@ -169,7 +169,6 @@ class SgaDaemon {
this.process.on("exit", (exitVal, signalName) => { this.process.on("exit", (exitVal, signalName) => {
sgaDaemons.delete(this); sgaDaemons.delete(this);
this.process = undefined; this.process = undefined;
this.config = undefined;
this.exitVal = exitVal; this.exitVal = exitVal;
this.signalName = signalName; this.signalName = signalName;
...@@ -313,15 +312,20 @@ async function clearAllResources() { ...@@ -313,15 +312,20 @@ async function clearAllResources() {
if (sga.terminate()) { if (sga.terminate()) {
await sga.terminated(); await sga.terminated();
} }
fs.rmdirSync(sga.config.project_root_dir, { recursive: true });
fs.rmdirSync(sga.config.algorithm_root_dir, { recursive: true });
fs.rmdirSync(sga.config.runtime_data_dir, { recursive: true });
fs.rmdirSync(sga.config.sandbox_root_dir, { recursive: true });
} }
for (let mock of registryMocks) { for (let mock of registryMocks) {
await mock.stop(); await mock.stop();
} }
} }
const uriPattern = /http:\/\//;
function checkRegistration(req, config) { function checkRegistration(req, config) {
const body = req.body; const body = req.body;
const uriPattern = /http:\/\//;
expect(body.name).toBe(config.sga_name); expect(body.name).toBe(config.sga_name);
expect(body.type).toBe("machine"); expect(body.type).toBe("machine");
expect(body.platform).toBe(config.platform); expect(body.platform).toBe(config.platform);
...@@ -356,6 +360,7 @@ function fillJobBody(id = "XPTO", params = {}, sandboxCount = 3) { ...@@ -356,6 +360,7 @@ function fillJobBody(id = "XPTO", params = {}, sandboxCount = 3) {
const waitMsec = (delay) => const waitMsec = (delay) =>
new Promise((resolve) => setTimeout(resolve, delay)); new Promise((resolve) => setTimeout(resolve, delay));
exports.uriPattern = uriPattern;
exports.waitMsec = waitMsec; exports.waitMsec = waitMsec;
exports.fillSgaConfig = fillSgaConfig; exports.fillSgaConfig = fillSgaConfig;
exports.SgaDaemon = SgaDaemon; exports.SgaDaemon = SgaDaemon;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment