Teste de relatório de jobs terminados ao reconectar.
[SOMA-6857][SOMA-7166][SOMA-6693]
... | ... | @@ -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); | ||
|
||
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 () { | ||
... | ... |