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,8 +108,13 @@ describe("Registering SGA", function () {
const [exitVal] = await sga.terminated();
expect(exitVal).toEqual(0);
});
});
describe("Mocked SGA", function () {
let config;
let regMockup;
let sga;
it("should receive requests to execute and inform its completion", async () => {
const jobBody = utils.fillJobBody();
const driverMockup = {
execute_command: `
......@@ -152,6 +157,13 @@ describe("Registering SGA", function () {
`,
};
afterEach(utils.clearAllResources);
beforeEach(() => {
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);
......@@ -167,10 +179,7 @@ describe("Registering SGA", function () {
});
}
const config = utils.fillSgaConfig();
const regMockup = new utils.RegistryService(config);
const sga = new utils.SgaDaemon(config, driverMockup);
it("should receive requests to execute and inform its completion", async () => {
spyOn(regMockup, "heartbeat").and.callThrough();
spyOn(regMockup, "status").and.callThrough();
......@@ -198,6 +207,52 @@ describe("Registering SGA", function () {
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 () {
......
......@@ -169,7 +169,6 @@ class SgaDaemon {
this.process.on("exit", (exitVal, signalName) => {
sgaDaemons.delete(this);
this.process = undefined;
this.config = undefined;
this.exitVal = exitVal;
this.signalName = signalName;
......@@ -313,15 +312,20 @@ async function clearAllResources() {
if (sga.terminate()) {
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) {
await mock.stop();
}
}
const uriPattern = /http:\/\//;
function checkRegistration(req, config) {
const body = req.body;
const uriPattern = /http:\/\//;
expect(body.name).toBe(config.sga_name);
expect(body.type).toBe("machine");
expect(body.platform).toBe(config.platform);
......@@ -356,6 +360,7 @@ function fillJobBody(id = "XPTO", params = {}, sandboxCount = 3) {
const waitMsec = (delay) =>
new Promise((resolve) => setTimeout(resolve, delay));
exports.uriPattern = uriPattern;
exports.waitMsec = waitMsec;
exports.fillSgaConfig = fillSgaConfig;
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